The Java Program: Widgets.java

  1 // Widgets.java -- All the "leaf" components
  2 /*
  3    Example of how to use this applet in an HTML file:
  4    <applet code=Widgets width=450 height=200></applet>
  5 */
  6 
  7 import java.applet.Applet;
  8 import java.awt.*;
  9 
 10 public class Widgets extends Applet {
 11 
 12    Label l;       Button b;       Checkbox x;     Choice ch;
 13    TextArea ta;   TextField tf;   List list;      Scrollbar s;   
 14 
 15    public void init() {
 16       setLayout (new FlowLayout (FlowLayout.LEFT, 3, 3));
 17 
 18       l = new Label ("Label", Label.RIGHT);
 19       b = new Button ("Button"); 
 20       x = new Checkbox ("Checkbox");
 21       ch = new Choice();
 22       ch.addItem ("first choice");
 23       ch.addItem ("second choice");
 24       ch.addItem ("third choice");
 25 
 26       // initial text value, row, cols
 27       ta = new TextArea ("TextArea", 3, 30);
 28 
 29       // initial text value, cols
 30       tf = new TextField ("TextField", 30);
 31 
 32       // rows, multiple selections
 33       list = new List (3, true);
 34       list.addItem ("one");
 35       list.addItem ("two");
 36       list.addItem ("three");
 37 
 38       // orientation, initial value, delta on click, min, maximum value
 39       s = new Scrollbar (Scrollbar.HORIZONTAL, 50, 10, 0, 100);
 40 
 41       // insert all the widgets in the applet aligned on left margin
 42       add (l);    add (b);    add (x);     add (ch);
 43       add (ta);   add (tf);   add (list);  add (s);
 44 
 45    }
 46 }