Java Reference
In-Depth Information
Graphic frame origin
Client area origin
Figure27-1FrameandtheClientAreaOrigin
TheconceptofaJavaprogramframeincludesthetitlebarandthewin-
dowborder,asshownin Figure27-1 . Sinceapplicationscannotdrawon
the title bar or the border, it is useful to change the frame origin to the
top-left corner of the client area, which is the screen area that applica-
tions can access. In order to translate the drawing origin from the frame
area to the client area you can use the translate() method of the graphics
class. The method receives two parameters which represent the x and the
y values by which the origin is to be moved. The size of the title bar and
the frame border can be obtained with the getInsets() method of the Con-
tainer class, as follows:
getInstets().left —> returns the width of the border
getInsets().top
—> returns the width of the titlebar
The call to translate() is made as follows:
g.translate(getInsets().left, getInsets().top);
After the translate() method executes, the origin of the drawing is lo-
cated at the top left corner of the application's client area.
 
Search WWH ::




Custom Search