(^420) | Event-Driven Input and Output
Reason for Test Case Input Values Expected Output Observed Output
Test add command 12.5,+ 12.500
Test subtract command 2.5,- 10.000
Test clear command none, Clear 0.000
Test window closing none Window disappears
Table 8.1 Test Plan for the CalculatorApplication
8.9 Testing and Debugging
Table 8.1 shows a partial test plan for the Calculatorapplication. The first test case assumes
that the calculator has an initial value of 0.0. Successive test cases use the preceding re-
sult as one of the two operands for a calculation. To be more thorough, we should check
that the application properly handles the closing of the window, and we should include
both negative and positive values.
Testing and Debugging Hints
1.Remember to label each input field with a prompting message.
2.Make certain that every field, label, and button follows the three basic steps:
declare a variable, instantiate an object, and add it to the pane.
3.Remember to specify a layout manager for a pane or panel.
4.The value in a TextFieldis a string. If you need to input a number, you must
use getTextto input the string, and then convert the string to a number using
methods such as Integer.parseIntand Double.parseDouble. Applying these
methods to a nonnumeric value causes the application to halt with an error
message such as Number Format Exception.
5.A button event listener declaration must follow the pattern of headings speci-
fied by the ActionListenerinterface. You can choose the name of the class, and
its modifiers, but the rest of the class heading and the method signature must
appear as shown in the examples in this book.
6.Once you have declared the button action listener class, you must perform
three steps to register the event listener: declare a variable of that class,
instantiate an object of the class and assign its address to the variable, and
register the listener by calling the button’s addActionListenermethod with the
variable as its argument.
7.Confirm that every part of an event loop is present, especially the exit condi-
tion.
T
E
A
M
F
L
Y
Team-Fly®