Java Reference
In-Depth Information
Title
Buttons
Space for menu bar
Content pane
Figure 2.1 Structure of a frame. The title text can be set. The position and appearance of the
buttons depend on the operating system. Further graphical components can be embedded
into the content pane
We now present the constructor, list some methods of JFrame and explain their
behaviour:
JFrame()
setVisible( boolean b)
setTitle(String title)
setSize( int width, int height)
setLocation( int horizontal, int vertical)
pack()
setDefaultCloseOperation( int operation)
JFrame() is the default constructor. It generates an untitled frame. 'Generate'
here means that the information for drawing the frame is provided. The frame
is, however, not shown on the screen. This is done by calling the method
!
setVisible , explained below.
setVisible(boolean b) makes the frame appear on the screen if b=true .If
a frame is visible then setVisible(false) makes it disappear but does not
destroy the information for drawing it. So, calling setVisible(true) on this
frame another time will make it visible again; we do not have to use the con-
structor a second time.
setTitle(String title) sets the title appearing in the title bar to title .
setSize(int width, int height) sets the width of the frame to width and the
height to height . These are outer measures in screen pixels.
setLocation(int horizontal, int vertical) moves the frame, so that its up-
per left corner is at position ( horizontal , vertical ). See also Figure 2.2.
Search WWH ::




Custom Search