CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Swing

Swing
Frames
Display a frame

A frame that doesn't contain any components

Common methods of the Frame class

Method Description
setTitle(String) Sets the title to the specified string.
setResizable(boolean) If the boolean value is true, the user can resize the frame.

A class that defines a frame

class FutureValueFrame extends JFrame
{
    public FutureValueFrame()
    {
        setTitle("Future Value Calculator");
        setBounds(267, 200, 267, 200);
        setResizable(false);
    }
}

A class that displays the frame

import javax.swing.*;

public class FutureValueApp
{
    public static void main(String[] args)
    {
        JFrame frame = new FutureValueFrame();
        frame.setVisible(true);
    }
}
Previous | Display a frame | Set the default close operation | Toolkit class | Next