Frame Windows in Java
The Frame windows in java working processes are described below:-
Working with Frame Windows in Java
After the applet, the type of window we will most often create is derived from Frame. We will use it to create child windows within applets, and top-level or child windows for applications. It creates a standard -style window. Following are two of Frame’s constructors:
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. Note that we cannot specify the dimensions of the window. Instead, we must set the size of the window after it has been created.
Setting the Windows Dimensions
The setSize( ) method is used to set the dimensions of the window. Its signature is shown below:
i. 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:
Dimension getSize( )
This method returns the current size of the window contained within the ‘width’ and ‘height’ fields of a Dimension object.
ii. Hiding and showing a Window
After a frame window has been created, it will not be visible until we call setVisible( ). Its signature is:
void set Visible(boolean visible flag)
The component is visible if the argument to this method is true. Otherwise, it is hidden.
iii. Setting a Windows Title
We can change the title in a frame window using setTitle( ), which has this general form:
void setTitle(String new title)
Here, ‘new title’ is the new title for the window.
iv.Closing a Frame Window
When using a frame window, our program must remove that window from the screen when it is closed, by calling set Visible(false). To intercept a window close event, we must implement the window closing( ) method of the Window Listener interface. Inside window Closing(), we must remove the window from the screen.
you may also like AWT Classes java.awt package