// Demonstrate text field. (Java 1.1 or later version)
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class TextFieldDemo extends Applet implements ActionListener
{

   TextField nameField, passField;

   public void init()
   {
	Label nameLabel = new Label( "Name: ", Label.RIGHT );
	Label passLabel = new Label( "Password: ", Label.RIGHT );
	nameField = new TextField( 12 );
	passField = new TextField( 8 );
	passField.setEchoChar( '?' );

	// Add controls
	add( nameLabel );
	add( nameField );
	add( passLabel );
	add( passField );

	// Register ActionListeners to receive action events.
	nameField.addActionListener( this );
	passField.addActionListener( this );
   }

   // ActionListeners.
   public void actionPerformed( ActionEvent ae )
   {
	repaint();
   }

   public void paint( Graphics g )
   {
	g.drawString( "Name: " + nameField.getText(), 6 ,60 );
	g.drawString( "Selected text in name: " + nameField.getSelectedText(), 6, 80 );
	g.drawString( "Password: " + passField.getText(), 6, 100 );
   }

   // main() is the entry point when called as an application.
   // main() is not used when run as an applet.
   public static void main ( String args[] )
   {
	Frame mainWindow = new Frame ( "Text Field Demo" );
	TextFieldDemo application = new TextFieldDemo ();

	mainWindow.setSize ( 200, 200 );
	mainWindow.add ( "Center", application );
	mainWindow.show ();
	application.init();
   }

}
