Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

Help

 

Training Index

by jGuru

Exercise  API Docs  About This Short Course  Short Course  Exercises

Help is available for each task.

Task 1

Create class DirectoryList as subclass of Frame. In the constructor, set the size to 400 x 500, create the list box in the north position, add the elements passed in to the constructor, and create a text area in the center position.

Use setSize() to set the size of the Frame. The components are added in the same manner as with an applet (a Frame is a specialized Container, as is an Applet).

Task 2

Add the following code to DirectoryList so that you can shut down the application window:

import java.awt.event.*;
...
// handle the WINDOW events here
addWindowListener(new WindowAdapter() {
  public void windowClosing(WindowEvent event) {
    setVisible(false);
    dispose();
    System.exit(0);
  }
});

Task 3

Add an actionPerformed() method to handle selection of the list elements. Upon selection (with a double-click operation), call displayFile() with the filename selected.

You should check to see that the component that caused the event was indeed the list box. Use an expression such as e.getSource() == list. Also, you should retrieve the selected item with list.getSelectedItem(), ensuring that the value returned is not null.

Copyright 1996-2000 jGuru.com. All Rights Reserved.