by Dinesh Thakur Category: AWT and Applets

The java.awt.Frame component is a Windows graphics system which has a title bar and borders, behaving like a normal GUI window. How is a subclass of java.awt.Container can contain other components being that its primary purpose. The default alignment components added to a Java.awt.BorderLayout.

When working with Frame objects, the following steps are basically followed to get a window to appear on the screen.

1. Create an object of type Frame.

2. Give the Frame object a size using setSize () method.

3. Make the Frame object appear on the screen by calling setVisible () method.

4. In order to close the window by clicking the close(X) button, you will have to insert the code for window closing event.

Following is a table that lists some of the methods of this class:

 

Method

Description

Frame ()

Constructs a new instance, invisible and without title.

Frame (String)

Constructs a new instance, invisible and entitled given

dispose ()

Releases the resources used by this component

getTitle ()

Gets the title of the window.

isResizable ()

Determines whether or not the window is sizable.

setMenuBa (MenuBar)

Adds the specified menu bar of the window.

setResizable (Boolean)

Specifies whether or not the window is sizable.

setTitle (String)

Specifies the window title.

import java.awt.*;

import java.awt.event.*;
class FrameJavaExample
{
    public static void main (String args[])
    {
             Frame frame = new Frame("Frame Java Example");
             //set the size of the frame
             frame.setSize(300,250);
             frame.addWindowListener(new WindowAdapter()
                          {
                             public void windowClosing(WindowEvent e)
                              {
                                System.exit(0);
                               }
                           });
                            frame.setVisible(true);
     }
}

Frame Java Example





About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles