import javax.swing.*;

/**
 * a first JFrame example
 * 
 * adapted from "Core Java", 9th. ed., p. 340
 *
 * NOTE: cannot run this via ssh; need to run it on
 *       a computer whose screen you can control
 * NOTE: overcommented for explanation purposes...!
 *
 * @author Cay Horstmann
 * @author adapted by Sharon Tuttle
 * @version 2015-09-15
 */

public class SimpleFrameTest
{
    /**
     * creates a simple frame
     * @param args not used here
     */
    
    public static void main(String[] args)
    {
        // what is SimpleFrame?
        //    it is a package-level class, a
        //    subclass of JFrame, to be defined
        //    later in this file
        
        SimpleFrame myFrame = new SimpleFrame();
        
        // because I want this application to finish
        //     when this frame is closed by the user
        //     I am going to specify that here
        // (we don't want the otherwise-usual default,
        //     where the frame is hidden but the
        //     application does not terminate...!)
        
        myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        // frames are NOT made visible when they
        //     are created -- so you can set them
        //     up and THEN make them visible
        
        myFrame.setVisible(true);
        
        // after making the frame visible,
        //    the main method exits. BUT that doesn't
        //    terminate the program -- just the main
        //    method's thread.
        // showing the frame activates a user interface
        //    thread that keeps the program alive
        //    (until it is closed, because of the
        //    setDefaultCloseOperation above)
    }
}

/**
 * a very simple empty frame
 */

class SimpleFrame extends JFrame
{
    // these are in pixels (picture element,
    //     one "dot" on your screen)
    
    public static final int DEFAULT_WIDTH = 300;
    public static final int DEFAULT_HEIGHT = 200;
    
    /**
     * construct a simplest frame instance
     */
    
    public SimpleFrame()
    {
        // a JFrame's default size is 0 pixels by 0 pixels!
        //     ...so we are resetting that to a more visible size
        //     using its setSize method

        this.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

        // we are also choosing to add text to its top,
        //     using its setTitle method

        this.setTitle("my first frame");
    }
}