Programming and Problem Solving with Java

(やまだぃちぅ) #1

422


7.When a dialog involves processing input from a field after a button has been
clicked, what part of the code is responsible for reading the field and
processing it? (pp. 394–396)
8.How do you register an event listener with a button? (pp. 387–390)
9.What Java interface does an event listener implement, and in what package is
the interface found? (pp. 387–390)
10.What are the parts of an event loop? (pp. 393–394)
11.Which method provides the string that we use to identify the source of an
event? (pp. 409–411)

Answers
1.A JFramecontains a content pane and the content pane contains user interface elements.2.The button
event handler 3.In the user’s actions and in the event handler 4.actionPerformed
5.private staticJTextField dataField;
dataField = newJTextField( 10 );
outPane.add(dataField);
6.outPane.add(newJLabel("Quick Check"));7.The event handler 8.With the addActionListenermethod
9.ActionListeneris found in java.awt.event.10.Initialization of the loop exit condition and the process, loop
entry, exit condition update, process update, and exit 11.getActionCommand

Exam Preparation Exercises


1.If aand bare intvariables with a= 5 and b= 2, what output does each of the fol-
lowing statements produce?
a.outPane.add(new JLabel("a = "+ a + "b = "+ b));
b.outPane.add(newJLabel("Sum:"+ a + b));
c. outPane.add(newJLabel("Sum: "+ a + b));
d.outPane.add(newJLabel(a / b + " feet"));
2.What does the following application display?
importjava.awt.*;
importjavax.swing.*;
public classExamPrep
{
public static voidmain(String[] args)
{
JFrame out;
Container outPane;
final intLBS = 10 ;
int price;
int cost;
charch;
out = newJFrame();
Free download pdf