/*
 * [TestJTextField.java]
 *
 * Summary: demonstrate the use of javax.swing.JTextField.
 *
 * 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.JTextField;
import javax.swing.SwingUtilities;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static java.lang.System.*;

/**
 * demonstrate the use of javax.swing.JTextField.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2009-01-01 initial version
 * @since 2009-01-01
 */
public final class TestJTextField
    {
    /**
     * Debugging harness for a Frame
     *
     * @param args command line arguments are ignored.
     */
    public static void main( String args[] )
        {
        SwingUtilities.invokeLater( new Runnable()
            {
            /**
             * fire up a JFrame on the Swing thread
             */
            public void run()
                {
                final JFrame jFrame = new JFrame();
                final Container contentPane = jFrame.getContentPane();
                final JTextField textfield = new JTextField( "this is a TEST" );
                textfield.setBackground( Color.BLACK );
                textfield.setForeground( Color.YELLOW );
                textfield.setFont( new Font( "Dialog", Font.BOLD, 15 ) );
                textfield.setHorizontalAlignment( JTextField.RIGHT );
                // provide some space around the inside
                textfield.setMargin( new Insets( 4, 4, 4, 4 ) );
                textfield.setEnabled( true );
                textfield.setEditable( true );
                textfield.addActionListener( new ActionListener()
                    {
                    /**
                     * Invoked when user hits enter after entering entire
                     * field..
                     */
                    public void actionPerformed( ActionEvent e )
                        {
                        out.println( textfield.getText() );
                        }
                    } );
                contentPane.add( textfield );
                jFrame.setSize( 150, 100 );
                jFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                jFrame.validate();
                jFrame.setVisible( true );
                }
            } );
        } // end main
    }