CS 2121 Introduction to Java:
Laboratory Exercise 5

April 2, 10 points


Overview

For this lab exercise, you should write an applet that has five simple components plus a text area. Action listeners and item listeners should be registered with each of the simple components to report events to the text area.

Information about configuring components and registering listeners for components used in this exercise can be obtained from the Components Information Applet.

The Overall Organization

The content pane of the applet should use a border layout. The simple components should be installed in a JPanel, which is added as the BorderLayout.WEST part of the content pane. The panel should have its preferred size set to 200 by 200.

The Text Area

The listeners for the simple components will all refer to the text area so it is easier if you declare it as an instance variable. It should be wrapped in a scroll pane which is added to the BorderLayout.CENTER part of the content pane. The scroll bars can be configured in the scroll pane constructor as in the following code.

    JScrollPane scrollPane = new JScrollPane(textArea,
	    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
	    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
Here, textArea is the name that you use for your text area variable.

The Simple Components

The panel in the West side of the content pane should contain five simple components:

The Listeners

Each of the simple components should have two listeners: an action listener and an item listener. The actionPerformed() or itemStateChanged() methods of these listeners should just append text to the text area indicating what component fired an event and what kind of event it was. For example, the actionPerformed() method for the action listener registered with the combo box can append the text "Box fired ActionEvent\n".

Demonstration Applet

The Lab Exercise 5 Demonstration Applet shows how your applet should look and behave when you are done.

Validating Your Applet

When you have you applet working get the attention of your instructor or TA and run it with appletviewer for him.