package com.mindprod.example;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Color;
import java.awt.Container;

/**
 * demonstrate the use of javax.swing.JFrame
 * <p/>
 * composed with IntelliJ IDEA
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0
 */
@SuppressWarnings( { "UnusedDeclaration" } )
final class TestJFrame
    {
    // ------------------------------ FIELDS ------------------------------

    /**
     * height of frame in pixels
     */
    private static final int height = 100;

    /**
     * width of frame in pixels
     */
    private static final int width = 300;
    private static final String RELEASE_DATE = "2006-03-06";

    /**
     * title for frame
     */
    private static final String TITLE_STRING = "JFrame Demo";

    /**
     * program version
     */
    private static final String VERSION_STRING = "1.0";

    // --------------------------- main() method ---------------------------

    /**
     * Debugging harness for a JFrame
     *
     * @param args command line arguments are ignored.
     */
    @SuppressWarnings( { "UnusedParameters" } )
    public static void main( String args[] )
        {
        // Invoke the run method on the Swing event dispatch thread
        // Sun now recommends you call ALL your GUI methods on the Swing
        // event thread, even the initial setup.
        // Could also use invokeAndWait and catch exceptions
        SwingUtilities.invokeLater( new Runnable()
        {
        /**
         * } fire up a JFrame on the Swing thread
         */
        public void run()
            {
            try
                {
                UIManager
                        .setLookAndFeel( new com.sun.java.swing.plaf.motif.MotifLookAndFeel() );
                }
            catch ( Exception e )
                {
                System.out.println( "Problem setting look and feel" );
                e.printStackTrace();
                }
            JFrame.setDefaultLookAndFeelDecorated( true );
            final JFrame jframe =
                    new JFrame( TITLE_STRING + " " + VERSION_STRING );
            Container contentPane = jframe.getContentPane();
            jframe.setSize( width, height );

            // Note that jframe.setBackground is almost useless.
            // You must set the background colour of the contentPane.
            contentPane.setBackground( Color.YELLOW );
            contentPane.setForeground( Color.BLUE );

            jframe.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            // Alternatively DISPOSE_ON_CLOSE, HIDE_ON_CLOSE (not recommended)
            // or DO_NOTHING_ON_CLOSE which requires a WindowClosing eventhandler
            // like a Frame closing
            // to decide what to do.
            // Note how JLabel inherits background but not foreground colour.
            contentPane.add( new JLabel( "Test" ) );
            jframe.validate();
            jframe.setVisible( true );
            // Nothing much to see, just an empty yellow frame, with word Test
            }
        } );
        }// end main
    }// end TestJFrame