Java Reference
In-Depth Information
The Closeable program provides a simple shell in which to create a
graphics window using the ActiveFrame class. In your own programs you
willprobablyneedtoconfiguretheWindowtosuityourpurposes.Forex-
ample, if your program needs to execute in a window of a size different
than the one in the sample code, or if it is initially located at a different
position in the desktop area, you would most likely use your own window
title. All of these and many other program parameters can be changed by
means of the corresponding methods of its superclasses, namely, Compo-
nent, Container, Window, and Frame. For example, you can resize the
program window by calling the setSize() method of the Component class,
as shown in the Closeable program.
On the Web
The program Closeable.java is located in the Chapter 26 folder at
www.crcpress.com . Alsointhisfolderisthesourcefor
ActiveFrame.java.
The Display Context
A Windows data structure that stores information about a particular de-
vice, such as the video display or a printer, is called a device context . The
JavacounterpartforadevicecontextisanobjectoftheGraphicsclass.The
Graphicsobjectcontainsinformationthatisnecessaryfordrawingopera-
tions, such as:
Theobjectthatistoreceivethedrawing.ThisisnormallyaComponent,but
it can also be an off-screen image.
A coordinate translation mode that controls the object's position on the
screen.
A clipping rectangle that limits output to the current frame.
A color used for drawing.
A font used for text output.
EveryJavaprogramthatrenderstextorgraphicsinaframemustrefer-
enceaGraphicsobject.TheGraphicsclass,whichispartoftheAWT,con-
tains over 35 methods, which can be used to draw lines, arcs, rectangles,
characters, bytes, bitmaps (called images in Java), ellipses, polylines,
among many graphic objects. The Graphics class is an abstract class so
you cannot instantiate objects of this class directly.
Search WWH ::




Custom Search