Programming and Problem Solving with Java

(やまだぃちぅ) #1

CASE STUDY


404


Now that we’ve identified these responsibilities, the user interface card can be low-
ered. As part of this process, however, we’ve determined that the input and the event
handling are part of the Stationclass. The user interface is not directly involved in the
data entry scenario. We should also note that each Stationrepresents a separate event
loop. What initializes and terminates these loops? Each loop is initialized by the user
interface instantiating a station, getting its user interface elements, and placing them
in the content pane. The loops are all terminated by closing the window. All of this
activity is handled in the initialization of the user interface, which occurs in the appli-
cation class. Let’s call it Rainfall.

Responsibility Algorithms:The Stationconstructor should take the name of the station
as a string and use it to form the first label, concatenating it with “Station” and “:”. This
label never changes again, so we can instantiate it anonymously. Our constructor needs
to create the rest of the user interface components described previously. They include

Class Name: Rainfall Superclass: Subclasses:


Responsibilities Collaborations
Initialize user interface

.
.
.

Station, JFrame, Container


Class Name: Station Superclass: Subclasses:


Responsibilities Collaborations
Create self

Get user interface elements
Handle button events

.
.
.

JButton, JLabel, JTextField


None
ActionHandler, JTextField, JLabel
Free download pdf