google search

Tuesday, April 13, 2010

WORKING WITH FRAME WINDOW

After the applet, the type of window you will most often create is derived from Frame.
You will use it to create child windows within applets, and top-level or child windows
for applications. As mentioned, it creates a standard-style window.
Here are two of Frame’s constructors:
Frame( )
Frame(String title)
The first form creates a standard window that does not contain a title. The second form
creates a window with the title specified by title. Notice that you cannot specify the
dimensions of the window. Instead, you must set the size of the window after it
has been created.
There are several methods you will use when working with Frame windows. They
are examined here.

Setting the Window’s Dimensions
The setSize( ) method is used to set the dimensions of the window. Its signature is
shown here:
void setSize(int newWidth, int newHeight)
void setSize(Dimension newSize)
The new size of the window is specified by newWidth and newHeight, or by the width
and height fields of the Dimension object passed in newSize. The dimensions are
specified in terms of pixels.
The getSize( ) method is used to obtain the current size of a window. Its signature
is shown here:
Dimension getSize( )
This method returns the current size of the window contained within the width and
height fields of a Dimension object.
Hiding and Showing a Window
After a frame window has been created, it will not be visible until you call
setVisible( ). Its signature is shown here:
void setVisible(boolean visibleFlag)
The component is visible if the argument to this method is true. Otherwise, it is hidden.
Setting a Window’s Title
You can change the title in a frame window using setTitle( ), which has this
general form:
void setTitle(String newTitle)
Here, newTitle is the new title for the window.
Closing a Frame Window
When using a frame window, your program must remove that window from the
screen when it is closed, by calling setVisible(false). To intercept a window-close
event, you must implement the windowClosing( ) method of the WindowListener
interface. Inside windowClosing( ), you must remove the window from the screen.
The example in the next section illustrates this technique.

0 comments:

  © Blogger templates ProBlogger Template by Ourblogtemplates.com 2008

Back to TOP