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
 

This exercise produces an application rather than an applet. This application should be run from the command line rather than from a page in a browser. (Applets cannot do file I/O for security reasons.)

Open a Frame with a list box and a text area. Using routines provided for you, display the list of files in the current directory in the list box. When the user double-clicks on an entry, display that file in the text area.

Skeleton Code

Tasks


  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.

  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);
      }
    });
    

  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.

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

Demonstration

This program cannot be run as an applet as it uses file I/O. Please run the solution from the command line as an application, or from an IDE window.

Next Exercise

Exercises

Short Course

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.