Introduction
to Interactive Programming
by Lynn Andrea
Stein
A Rethinking
CS101 Project
|
|
|
|
Component Name |
Description |
Main Event Generated |
---|---|---|
java.awt.Button |
Clickable button with label. Clicking on this component generates an ActionEvent. |
java.awt.event.ActionEvent |
java.awt.Checkbox |
Label with on/off mark. Clicking this item causes its state (checked/unchecked) to change. If a Checkbox is part of a CheckboxGroup, at most one Checkbox in the group can be selected. |
java.awt.event.ItemEvent |
java.awt.Choice |
Popup with a list of labels from which a single item can be selected |
java.awt.event.ItemEvent |
java.awt.Label |
A non-editable text item. |
none |
java.awt.List |
List of labels, each of which may be selected or not. Clicking an item toggles (flips) its state. |
java.awt.event.ItemEvent |
java.awt.TextArea |
A multi-line text box. |
java.awt.event.TextEvent |
java.awt.TextField |
Box into which a single line of text may be typed. Hitting the return key causes an ActionEvent. |
java.awt.event.ActionEvent |
The major methods of each widget type are listed in separate sidebars, below.
|
|
|
|
|
|
|
|
Event Class |
Notable Event Methods |
---|---|
ActionEvent |
public String getActionCommand(); can be used
to disambiguate source. |
MouseEvent |
public Component getComponent(); same as
getSource(), but typed correctly |
ItemEvent |
public Object getItem(); returns selected
item |
WindowEvent |
public Window getWindow(); same as getSource(), but typed correctly |
ComponentEvent |
public Component getComponent(); same as getSource(), but typed correctly |
ContainerEvent |
public Component getChild(); who was added
or removed |
|
|
Event Class |
Listener Interface |
Adapter Class |
Listener/Adapter methods |
---|---|---|---|
ActionEvent |
ActionListener |
|
actionPerformed( ActionEvent e ); |
MouseEvent |
MouseListener
MouseMotionListener |
MouseAdapter
MouseMotionAdapter |
mouseClicked( MouseEvent e ); mouseDragged( MouseEvent e ); |
ItemEvent |
ItemListener |
|
itemStateChanged( ItemEvent e ); |
WindowEvent |
WindowListener |
WindowAdapter |
windowActivated( WindowEvent e ); |
ComponentEvent |
ComponentListener |
ComponentAdapter |
componentHidden( ComponentEvent e ); |
ContainerEvent |
ContainerListener |
ContainerAdapter |
componentAdded( ContainerEvent e) |
FocusEvent |
FocusListener |
FocusAdapter |
focusGained( FocusEvent e ); |
TextEvent |
TextListener |
|
textValueChanged( TextEvent e ); |
KeyEvent |
KeyListener |
KeyAdapter |
keyPressed( KeyEvent e ); |
© 2003 Lynn Andrea Stein
This chapter is excerpted from a draft of Introduction to Interactive Programming In Java, a forthcoming textbook. It is a part of the course materials developed as a part of Lynn Andrea Stein's Rethinking CS101 Project at the Computers and Cognition Laboratory of the Franklin W. Olin College of Engineering and formerly at the MIT AI Lab and the Department of Electrical Engineering and Computer Science at the Massachusetts Institute of Technology.
Questions or comments:
<cs101-webmaster@olin.edu>