1  /* 
  2     File: Download.java
  3  
  4     archiving, compressing, and downloading a server
  5     directory on-the-fly
  6  */
  7  
  8  import java.applet.Applet;
  9  import java.awt.*;
 10  import java.awt.event.*;
 11  
 12  public class Download extends Applet 
 13                        implements ActionListener, ItemListener {
 14  
 15    private Label directoryLabel, formatLabel, fileLabel;
 16    private Choice directoryList, formatList;
 17    private Button downloadButton;
 18    
 19    public void init() {
 20      setBackground( Color.white );
 21  
 22      directoryLabel = 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      
 34      formatLabel = new Label( "   Format:  ", Label.RIGHT );
 35      
 36      formatList = new Choice();
 37      formatList.addItem( ".zip"    );
 38      formatList.addItem( ".tar.Z"  );
 39      formatList.addItem( ".tar.gz" );
 40      formatList.addItem( ".sit"    );
 41      // Select ".tar.gz" as the default menu choice:
 42      formatList.select(2);
 43      
 44      fileLabel = new Label();
 45      fileLabel.setAlignment( Label.LEFT );
 46      updateLabel();
 47      
 48      downloadButton = new Button( "Download" );
 49      
 50      int rows = 2, cols = 3;
 51      setLayout( new GridLayout( rows, cols ) );
 52      add( directoryLabel ); add( directoryList ); add( fileLabel );
 53      add( formatLabel ); add( formatList ); add( downloadButton );
 54      
 55      directoryList.addItemListener( this );
 56      formatList.addItemListener( this );
 57      downloadButton.addActionListener( this );
 58    }
 59    
 60    public void actionPerformed( ActionEvent event ) {
 61      showStatus( "Not yet implemented!" );
 62    }
 63    
 64    public void itemStateChanged( ItemEvent event ) {
 65      updateLabel();
 66    }
 67    
 68    public void updateLabel() {
 69      String s = directoryList.getSelectedItem();
 70      s += formatList.getSelectedItem();
 71      fileLabel.setText( "File:  " + s );
 72    }
 73  
 74  }