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 );
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 );
}
} );
}
}