Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
Print Button
 

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.


Print Button
[ This page was updated: 14-Jul-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.