Java Reference
In-Depth Information
Answers to Review Questions
1.
The source of the event, the listener of the event, and interface that provides the
mechanism for the source and listener to communicate.
2.
Clicking a button generates an ActionEvent, so the answer is b. There is no such event
as MouseClickedEvent, although clicking a button does generate a MouseEvent.
3.
One method named public void actionPerformed(ActionEvent a).
4.
False. There are many components that do not generate an ActionEvent.
5.
True. All components are the source of mouse events, as can be determined by the
addMouseListener() method of the java.awt.Component class.
6.
False. A component can have any number of listeners (zero or more).
7.
To listen to a KeyEvent, you need to write a class that implements the KeyListener
interface. Register your listener by invoking the addKeyListener() method on the
component you want to listen to.
8.
The windowClosing() method is invoked when a user attempts to close a window by
clicking the X, so the answer is c.
9.
Yes, the MouseListener interface has a corresponding event adapter class named
MouseAdapter.
10.
Clicking a Checkbox generates an ItemEvent. Clicking a JCheckBox generates an
ItemEvent and also a ChangeEvent.
11.
The Checkbox and CheckboxGroup classes.
12.
The JCheckBox and ButtonGroup classes.
13.
Typing anything in a text area generates both a key event and a text event. Note that a
text area does not generate action events, so the answer is f.
14.
True. The constructor of JScrollPane has a parameter of type java.awt.Component, so
it can actually be used as a scroll pane for AWT components as well.
15.
The component that has focus is the component that receives the key events gener-
ated from the user's typing on the keyboard.
16.
Clicking once on a List item generates an ItemEvent. Doing the same on a JList item
generates a ListSelectionEvent. Note that JList components never generate an
ItemEvent.
17.
Double-clicking on a List item generates an ActionEvent. Again, doing the same on a
JList item generates a ListSelectionEvent. Note that JList components never generate
an ActionEvent either.
18.
A Choice generates an ItemEvent, so the answer is d.
Search WWH ::




Custom Search