26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12 Graphical User Interface Components: Part 1 703<br />

After JPanel but<strong>to</strong>nPanel is created at line 27, lines 28–29 set but<strong>to</strong>n-<br />

Panel’s layout <strong>to</strong> a GridLayout of one row and five columns (there are five JBut<strong>to</strong>ns<br />

in array but<strong>to</strong>ns). The five JBut<strong>to</strong>ns in array but<strong>to</strong>ns are added <strong>to</strong> the JPanel in<br />

the loop with line 35. Notice that the but<strong>to</strong>ns are added directly <strong>to</strong> the JPanel—class<br />

JPanel does not have a content pane like an applet or a JFrame. Line 38 uses the content<br />

pane’s default BorderLayout <strong>to</strong> add but<strong>to</strong>nPanel <strong>to</strong> the SOUTH region. Note that<br />

the SOUTH region is as tall as the but<strong>to</strong>ns on but<strong>to</strong>nPanel. A JPanel is sized <strong>to</strong> the<br />

components it contains. As more components are added, the JPanel grows (according <strong>to</strong><br />

the restrictions of its layout manager) <strong>to</strong> accommodate the components. Resize the window<br />

<strong>to</strong> see how the layout manager affects the size of the JBut<strong>to</strong>ns.<br />

12.16 (Optional Case Study) Thinking About Objects: Use<br />

Cases<br />

The previous eight “Thinking About Objects” sections have concentrated on the eleva<strong>to</strong>rsimulation<br />

model. We have identified and honed the structure and behavior of our system.<br />

In this section, we model the interaction between the user and our eleva<strong>to</strong>r simulation<br />

through the UML use-case diagram, which describes the sets of scenarios that occur between<br />

the user and the system.<br />

Use-Case Diagrams<br />

When developers begin a project, they rarely start with as detailed a problem statement as<br />

the one we provided in Section 2.9. This document and others are the result of the objec<strong>to</strong>riented<br />

analysis (OOA) phase. In this phase you meet with the people who want you <strong>to</strong><br />

build a system and with the people who will eventually use that system. You use the information<br />

gained in these meetings <strong>to</strong> compile a list of system requirements. These requirements<br />

guide you and your fellow developers as you design the system. In our case study,<br />

the problem statement described the requirements of our eleva<strong>to</strong>r simulation in sufficient<br />

detail that you did not need <strong>to</strong> go through an analysis phase. The analysis phase is enormously<br />

important—you should consult the references we provide in Section 2.9 <strong>to</strong> learn<br />

more about object-oriented analysis.<br />

The UML provides the use-case diagram <strong>to</strong> facilitate requirements gathering. This diagram<br />

models the interactions between the system’s external clients and the use cases of the<br />

system. Each use case represents a different capability that the system provides <strong>to</strong> clients.<br />

For example, au<strong>to</strong>mated teller machines typically have several use cases, including<br />

“Deposit Money,” “Withdraw Money” and “Transfer Funds.”<br />

In larger systems, use-case diagrams are indispensable <strong>to</strong>ols that help system designers<br />

remain focused on satisfying the users’ needs. The goal of the use-case diagram is <strong>to</strong> show<br />

the kinds of interactions users have with a system without providing the details of those<br />

interactions: those details are, of course, provided in other UML diagrams.<br />

Figure 12.28 shows the use-case diagram for our eleva<strong>to</strong>r simulation. The stick figure<br />

represents an ac<strong>to</strong>r, which, in turn, represents a set of roles that an external entity—such as<br />

a person or another system—can play. Consider again our au<strong>to</strong>mated teller machine<br />

example. The ac<strong>to</strong>r is a BankCus<strong>to</strong>mer who can deposit, withdraw and transfer funds<br />

from the ATM. In this sense, BankCus<strong>to</strong>mer is more like a class rather than an object—<br />

it is not an actual person, but rather describes the roles that a real person—when playing the<br />

part of a BankCus<strong>to</strong>mer—can perform while interacting with the ATM (deposit, with-<br />

© Copyright 1992–2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!