home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / src / java / awt / test / textfiel.jav < prev    next >
Encoding:
Text File  |  1995-10-30  |  2.4 KB  |  93 lines

  1. /*
  2.  * @(#)TextFieldTest.java    1.4 95/09/06 Arthur van Hoff
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. import java.awt.*;
  21.  
  22. /**
  23.  * A test of a Container with BorderLayout.
  24.  */
  25. public class TextFieldTest extends Frame {
  26.     TextField t1;
  27.     TextField t2;
  28.     TextField t3;
  29.  
  30.     public TextFieldTest() {
  31.     super("TextFieldTest");
  32.     
  33.     Panel p = new Panel();
  34.     p.setLayout(new GridLayout(0, 2));
  35.     p.add(new Label("name"));
  36.     p.add(t1 = new TextField("Beatrix Butterfly"));
  37.     t1.setForeground(Color.blue);
  38.  
  39.     p.add(new Label("address"));
  40.     p.add(t2 = new TextField("3 Green Fields Lane"));
  41.  
  42.     p.add(new Label("city"));
  43.     p.add(t3 = new TextField("SunnyHills"));
  44.     t3.setEditable(false);
  45.  
  46.     add("Center", p);
  47.  
  48.     p = new Panel();
  49.     Button b;
  50.     p.add(b = new Button("clear"));
  51.     b.setForeground(Color.red);
  52.     p.add(new Button("reset"));
  53.     p.add(new Button("select"));
  54.     p.add(new Button("print"));
  55.     add("South", p);
  56.     move(200, 100);
  57.     pack();
  58.     show();
  59.     }
  60.  
  61.     public boolean handleEvent(Event evt) {
  62.     if (evt.id == Event.ACTION_EVENT) {
  63.         if ("clear".equals(evt.arg)) {
  64.         t1.setText("");
  65.         t2.setText("");
  66.         return true;
  67.         }
  68.         if ("reset".equals(evt.arg)) {
  69.         t1.setText("Arthur van Hoff");
  70.         t2.setText("2235 Wyandotte St");
  71.         return true;
  72.         }
  73.         if ("select".equals(evt.arg)) {
  74.         t1.selectAll();
  75.         return true;
  76.         }
  77.         if ("print".equals(evt.arg)) {
  78.         System.out.println("-- values --");
  79.         System.out.println("name=" + t1.getText());
  80.         System.out.println("address=" + t2.getText());
  81.         System.out.println("city=" + t3.getText());
  82.         return true;
  83.         }
  84.     }
  85.     System.out.println(evt.toString());
  86.     return true;
  87.     }
  88.  
  89.     public static void main(String args[]) {
  90.     new TextFieldTest();
  91.     }
  92. }
  93.