Usage

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.

Package

java.awt

Class

java.awt.Frame

Parent Classes

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

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.

Arguments

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

Example - Frame2.class

Source Code - Frame2.java

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