1  /*
  2   *  File:  ChoiceDemo.java
  3   *
  4   *  Choosing items from a drop-down list
  5   *
  6   *  Copyright:  Northeast Parallel Architectures Center
  7   *  
  8   */
  9  
 10  import java.awt.Color;
 11  import java.awt.Label;
 12  import java.awt.Choice;
 13  
 14  public class ChoiceDemo extends java.applet.Applet {
 15  
 16    private Label label1, label2;
 17    private Choice directoryList, formatList;
 18  
 19    public void init() {
 20      setBackground( Color.white );
 21  
 22      label1 = new Label( "Directory:  ", Label.RIGHT );
 23      
 24      directoryList = new Choice();
 25      directoryList.addItem( "HTML"       );
 26      directoryList.addItem( "JavaScript" );
 27      directoryList.addItem( "CGI"        );
 28      directoryList.addItem( "Java"       );
 29      directoryList.addItem( "JDBC"       );
 30      directoryList.addItem( "VRML"       );
 31      // Select "JavaScript" as the default menu choice:
 32      directoryList.select(1);
 33      directoryList.setBackground( Color.white );
 34  
 35      label2 = new Label( "   Format:  ", Label.RIGHT );
 36      
 37      formatList = new Choice();
 38      formatList.addItem( ".zip"    );
 39      formatList.addItem( ".tar.Z"  );
 40      formatList.addItem( ".tar.gz" );
 41      formatList.addItem( ".sit"    );
 42      // Select ".tar.gz" as the default menu choice:
 43      formatList.select(2);
 44      formatList.setBackground( Color.white );
 45      
 46      add( label1 ); add( directoryList );
 47      add( label2 ); add( formatList );
 48    }
 49    
 50  }