/*
 * [TestJFrame.java]
 *
 * Summary: demonstrate the use of javax.swing.JFrame.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2009-01-01 initial version
 */
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;

import static java.lang.System.*;

/**
 * demonstrate the use of javax.swing.JFrame.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2009-01-01 initial version
 * @since 2009-01-01
 */
@SuppressWarnings( { "UnusedDeclaration" } )
final class TestJFrame
    {
    /**
     * 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";

    /**
     * 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 )
                    {
                    err.println();
                    e.printStackTrace( err );
                    err.println( "Problem setting look and feel" );
                    err.println();
                    }
                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
                }
            } );
        }
    }