A Frame is a top-level window with a title and a border.  It is normally used as the main window of a standalone application.





Parent Classes

java.awt.Frame implements MenuContainer
java.awt.Window implements Accessible
java.awt.Component implements ImageObserver, MenuContainer, Serializable

Common Public Constructors

Frame ()
Creates a blank Button instance.
Frame (String Text)
Creates a Frame instance with the specified text in the title bar.

Common Public Methods

addWindowListener(WindowListener Handler)
Configures a window event handler for the frame.
setBackground (Color BackgroundColor)
Sets the background color of the frame.
setFont (Font TextFont)
Sets the font for this component.
setForeground (Color TextColor)
Sets the color of the text for the frame.
setSize (int Width, int Height)
Resizes this window so that it has the specified Width and Height.
setTitle (String Text)
Sets the text for the title bar.
show ()
Makes the window visible.


The color to be used for the background of the button.
The object which handles window events from this frame.
The text to appear in the title bar.
The color to be used for the text of the button.
The font to be used for the text of the button.

Example - Frame2.class

Source Code -

import java.awt.*;
import java.awt.event.*;

public class Frame2 extends Frame {
    private Closer Handler;
    Frame2 () {
        Handler = new Closer ();
        setTitle ("Frame Example");
        setSize (300,120);
        addWindowListener (Handler);
        show ();

    public static void main (String args[]) {
        Frame f;
        f = new Frame2 ();
class Closer extends WindowAdapter {
    public void windowClosing (WindowEvent event) {
        System.exit (0);

Reference Links

Swing JFrame Example

External Links

Sun Java site Class Frame API Java 1.6
Sun Java site Class Frame API Java 1.5
Sun Java site Class Frame API Java 1.4.2
Sun Java site Class Frame API Java 1.3.1