import javax.swing.*;

/** DemoHelloWorld - simple Java program using Swing.<p>
*
* This is a bare-bones program that creates a <i>graphical user interface</i>
* (GUI) using Swing components.
* It is organized much the same as simpler Java applications limited to
* console I/O (character input via the keyboard,
* character output to the system display).
* In the
* next demo program (<code>DemoHelloWorld2</code>) we'll show essentially
* the same program, but with a much different organization.  This will prepare
* us for creating larger Swing applications using numerous features
* common in GUI applications.  For the moment, however,
* let's just examine the basic steps necessary to create a GUI application
* using Swing.<p>
*
* The first
* order of business is to identify the classes from the JFC
* (Java Foundation Classes) used in the application.
* This is done
* using an <code>import</code> statement.  In this demo, we need just
* one such statement:
*
* <pre>
*     import javax.swing.*;
* </pre>
*
* This allows us to use any class from the <code>javax.swing</code>
* package.<p>
*
* Following the <code>import</code> statement,
* there is the definition of
* a public class having the same name as the filename,
* and within this class there is the definition of a
* method called <code>main</code>.  The <code>main</code> method
* executes when the class is loaded by the run-time interpreter.
* Here's the code:<p>
*
* <pre>
*     public class DemoHelloWorld
*     {
*        public static void main(String[] args)
*        {
*           ...
*        }
*     }
* </pre>
*
* Within the <code>main</code> method,
* the primary task is to create and configure a <i>top-level
* container</i>.  This is a requirement of every Swing program.
* A top-level
* container provides the infrastructure for Swing's GUI components to
* present themselves (aka <i>painting</i>) and to respond to
* user actions (aka <i>event handling</i>).  Swing's most common
* top-level container is <code>JFrame</code>, which is used as the
* primary window for an application.  (There are two other
* top-level containers: <code>JDialog</code>,
* and <code>JApplet</code>.)<p>
*
* The first line in <code>main</code> instantiates a
* <code>JFrame</code> object named <code>frame</code>:<p>
*
* <pre>
*     JFrame frame = new JFrame("DemoHelloWorld");
* </pre>
*
* The string argument is simply the text that appears in the title
* bar of the application window.  A convention we'll
* use in all our demo programs is to present the name of the
* program in the title bar of the application window.<p>
*
* The second line instantiates a <code>JLabel</code> object:<p>
*
* <pre>
*     JLabel message = new JLabel("Hello World");
* </pre>
*
* The string argument in this case is the message presented
* within the application window.
* <code>JLabel</code> is a simple Swing
* component that presents some text in a window.  Typically,
* it is used to adorn a nearby component, such as a text
* field; however, its purpose here is just
* to present a simple message in our application window.<p>
*
* The following two lines create a <code>JPanel</code> named
* <code>panel</code> and add the label to the panel:<p>
*
* <pre>
*     JPanel panel = new JPanel();
*     panel.add(message);
* </pre>
*
* <code>JPanel</code> is an <i>intermediate container</i>.
* It serves only as a place in which to put and position components.
* A panel is sometimes called a <i>pane</i>.  The <code>JLabel</code>
* is placed in the panel using the <code>add</code> method of the
* <code>JPanel</code> class.  (In fact, <code>add</code> is an
* inherited method.  It is defined in the <code>Container</code> class.
* Consult the Java API Specification for more details.)
* <p>
*
* The next line establishes the panel as the <i>content pane</i>
* for our <code>JFrame</code>:
*
* <pre>
*     frame.setContentPane(panel);
* </pre>
*
* This somewhat obscure step is a
* requirement of all Swing  programs.  The content pane contains the
* visible components of a top-level container.<p>
*
* The next line provides a simple mechanism to terminate the application
* by clicking the close button in the top-right corner of the
* application window.
*
* <pre>
*     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
* </pre>
*
* Without this step, closing the window would make the application
* window disappear, but would leave the application running.  Connecting
* these two primitive actions
* -- closing the window <i>and</i> terminating the application --
* requires this simple statement.<p>
* 
* The next line acts like a command to the frame telling it to
* re-evaluate its contents to determine the size and position
* of each component:<p>
*
* <pre>
*     frame.pack();
* </pre>
*
* Finally, the frame is made visible as follows:<p>
*
* <pre>
*     frame.show();
* </pre>
*
* Here's a screen snap of the application upon launch:<p>
*
* <center><img src="DemoHelloWorld-1.gif"></center>
*
* @see <a href="DemoHelloWorld.java">source code</a>
* @author Scott MacKenzie, 2004
*/
public class DemoHelloWorld
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame("DemoHelloWorld");
      JLabel message = new JLabel("Hello World");
      JPanel panel = new JPanel();
      panel.add(message);
      frame.setContentPane(panel);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.show();
   }
}

