// Fig. 10.10: MyTextfield.java
// Demonstrating the TextField class.
import java.awt.*;
import java.awt.event.*;

public class MyTextfield extends Frame {
   private TextField text1, text2, text3, text4;
   private TextFieldHandler handler;

   MyTextfield( String name )
   {
      super( name );
   }

   public void init()
   {
      setBackground( Color.lightGray );
      setSize(300, 100);
      // setup handler object
      handler = new TextFieldHandler( );

      // construct textfield with default sizing
      text1 = new TextField();
      text1.addActionListener( handler );
      add( text1 );

      // construct textfield with default text
      text2 = new TextField( "Enter text here" );
      text2.addActionListener( handler );
      add( text2 );

      // construct textfield with default text
      text3 = new TextField( "Hidden text" );
      text3.setEchoChar( '*' );
      text3.addActionListener( handler );
      add( text3 );

      // construct textfield with default text and
      // 40 visible elements and no event handler
      text4 = new TextField( "Uneditable text field", 40 );
      text4.setEditable( false );
      add( text4 );
      setLayout( new FlowLayout( FlowLayout.CENTER ) );
   }

  public static void main(String argv[]){
    System.out.println( "wejście do main..." );
    MyTextfield f = new MyTextfield("Pole tekstowe");
    f.init();
    f.show();
    System.out.println( "wyjście z main..." );
  }

}

class TextFieldHandler implements ActionListener {

   public void actionPerformed( ActionEvent e )
   {
      System.out.println( "Text is: " +
         e.getActionCommand() );
   }
}
