go to previous page   go to home page   go to next page



Program with two Frames

This program creates (and displays) two frames. One frame is the "master" frame. Click its close button, and everything closes down. The other frame is temporary. Click its close button, and only it is closed.

import java.awt.*;
import javax.swing.*;

public class TwoTestFrames
  public static void main ( String[] args )
    int height=100, width=200;
    JFrame master = new JFrame("Click to Close Everything");
    JFrame temp = new JFrame("Click to Close Just This");

    master.setVisible( true );
    master.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    master.setSize( 400, 300 );
    temp.setVisible( true );
    temp.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE  );
    temp.setSize( 300, 200 );


Of course, in a sensible program the frames would be doing something more than just displaying themselves. We will get to this in a few chapters.


Is it possible to define a class that uses JFrame as a base (a parent) class?