Programming and Problem Solving with Java
(^400) | Event-Driven Input and Output public classCopyString { // Define a button handler private static classButtonHandler imp ...
8.7 Reading Data in an Event Handler | 401 After the user enters a string and clicks the copy button, the frame appears as follo ...
CASE STUDY 402 TOTALING RAINFALL AMOUNTS Problem:You are working for a scientific research project that is keeping track of the ...
CASE STUDY^403 Scenarios:What happens when an observer calls in with a rainfall amount? The user in- terface CRC card is raised, ...
CASE STUDY 404 Now that we’ve identified these responsibilities, the user interface card can be low- ered. As part of this proce ...
CASE STUDY^405 the data entry field, the button, and the output label. We want each instance of the class to have its own copy o ...
CASE STUDY 406 fields. So, we must make the event handler be an instance class (not static). What does the event handler do when ...
CASE STUDY^407 panel.add(amountField); panel.add(enter); panel.add(outputLabel); } // End Station constructor publicJPanel getPa ...
CASE STUDY 408 Let’s call the application class Rainfall. Here is code for the complete application: //************************* ...
CASE STUDY^409 With applications that input data from fields, the most common error is to try to as- sign the field contents dir ...
(^410) | Event-Driven Input and Output to the button to identify it. We access the string by calling the value-returning method ...
8.8 Handling Multiple Button Events | 411 In the preceding example, we introduced two new methods,disposeand exit. The dis- pose ...
CASE STUDY 412 A SIMPLE CALCULATOR Problem:It’s useful to have a calculator that you can display on your computer screen when yo ...
CASE STUDY^413 Scenarios:What happens when the application begins? The user interface card is raised. It must set up the user in ...
CASE STUDY 414 The clear button has a different function than the other buttons. When it is clicked, the register is set to zero ...
CASE STUDY^415 Before we go on, let’s simplify the problem somewhat. We will first create a calcula- tor with only plus and minu ...
CASE STUDY 416 We still have one more step in mainto flesh out. Registering an event listener for a button involves three steps: ...
CASE STUDY^417 The algorithm for handling the Clear button is even simpler; all we have to do is set the register to zero as wel ...
CASE STUDY 418 staticJButton subtract; // Subtract button staticJButton clear; // Clear button // Define event listener for nume ...
CASE STUDY^419 // Instantiate button objects add = newJButton("+"); subtract = newJButton("-"); clear = newJButton("Clear"); // ...
«
17
18
19
20
21
22
23
24
25
26
»
Free download pdf