package com.mindprod.example;

import com.mindprod.common11.FontFactory;

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;

/**
 * demonstrate the use of javax.swing.JTextField
 * <p/>
 * composed with IntelliJ IDEA
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0
 */
public final class TestJTextField
    {
    // --------------------------- main() method ---------------------------

    /**
     * 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( FontFactory.build( "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 )
                {
                System.out.println( textfield.getText() );
                }
            } );

            contentPane.add( textfield );

            jFrame.setSize( 150, 100 );
            jFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            jFrame.validate();
            jFrame.setVisible( true );
            }
        } );
        }// end main
    }