import javax.swing.*;

/** DemoHelloWorld2 - same as <code>DemoHelloWorld</code> except re-organized.<p>
*
* This demo program will help us make the
* transition
* from the conventional organization of console applications
* to a more appropriate organization for full-blown
* GUI applications.  The organization
* shown here is consistently used in all our GUI application demos.
* <p>
*
* The main ingredient of a GUI is the "application window".
* As we saw in <code>DemoHelloWorld</code>, the application
* window is an instance of Swing's most common top-level
* container, <code>JFrame</code>.  This is so fundamental
* to the design of GUI applications that it makes sense
* to separate the instantiation and configuration of the
* application window from
* the <code>main</code> method.  We do this by defining
* our application's window 
* as a separate custom class -- an extension of
* <code>JFrame</code>.
* <p>
*
* We limit the <code>main</code> method to a few simple
* tasks pertaining to getting the application up and running.
* These include instantiating the
* application window, defining a default termination operation
* for it, giving it a title, telling it to pack itself
* (i.e., compute the size and position of all its components), and,
* finally, making the application window visible.
* These operations are preformed
* in the <code>main</code> method with the following five statements:<p>
*
* <pre>
*     DemoHelloWorld2Frame frame = new DemoHelloWorld2Frame();
*     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
*     frame.setTitle("DemoHelloWorld2");
*     frame.pack();
*     frame.show();
* </pre>
*
* Following this, the <code>main</code> method terminates.  However, the program
* continues to run because our GUI's window has been
* instantiated and <i>realized</i> (via the <code>pack</code> and
* <code>show</code>
* methods).  The application window appears on the screen, and
* it can be moved, resized, minimized, or maximized.
* If the application includes GUI components
* such as buttons, the user may interact with these according to the
* design of the application.  (We'll see this in our next demo
* program.)
* <p>
*
* Generally speaking, the <code>main</code> method will be quite short.
* The
* real work is performed in the code that defines the
* contents and interactions
* supported by our extended <code>JFrame</code>.
* <p>
*
* In this simple application, our extended <code>JFrame</code> --
* the application window -- includes just a single method, the
* constructor.  Besides the implicit call to the superclass constructor,
* there is very little work to do.  The constructor includes
* just four statements:
* <p>
*
* <pre>
*      JLabel message = new JLabel("Hello World");
*      JPanel panel = new JPanel();
*      panel.add(message);
*      this.setContentPane(panel);
* </pre>
*
* The tasks are the same as described earlier, in our description
* of <code>DemoHelloWorld</code>.
* <p>
* 
* Screen snap...<b>
* <center><img src="DemoHelloWorld2-1.gif"></center>
*
* @see <a href="DemoHelloWorld2.java">source code</a>
* @author Scott MacKenzie, 2003
*/
public class DemoHelloWorld2
{
   public static void main(String[] args)
   {
      DemoHelloWorld2Frame frame = new DemoHelloWorld2Frame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setTitle("DemoHelloWorld2");
      frame.pack();
      frame.show();
   }
}

class DemoHelloWorld2Frame extends JFrame
{
   DemoHelloWorld2Frame()
   {
      JLabel message = new JLabel("Hello World");
      JPanel panel = new JPanel();
      panel.add(message);
      this.setContentPane(panel);
   }   
}

