Ch 14 – Advanced GUI Applications - SaigonTech

jetmorebrisketΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 4 χρόνια και 10 μήνες)

292 εμφανίσεις

GUI Applications

JCheckBox

Contents

A.
Problem: An Order Calculator for the
Brandi’s Bagel House

B.
Solution

C.
Exercise: Implementing a Separate
Model

A. Problem: An Order Calculator for
the Brandi’s Bagel House


Brandi’s Bagel House has a bagel and
coffee delivery service for the businesses
in her neighborhood


Customers may call in and order white and
whole wheat bagels with a variety of
toppings


In addition, customers may order three
different types of coffee (Delivery for
coffee alone is not available, however)


Here is a complete price list


Bagels


White bagel $1.25


Whole wheat bagel $1.50


Toppings


Cream cheese $0.50


Butter $0.25


Peach jelly $0.75


Blueberry jam $0.75


Coffee


Regular coffee $1.25


Decaf coffee $1.25


Cappuccino @2.00


Brandi, the owner, needs an “order
calculator” application that her staff can
use to calculate the price of an order as it
is called in


The application should display the
subtotal, the amount of a 6% sales tax,
and the total of the order


B. Solution

1.
Developing the View

2.
Implementing Event Handlers

3.1. Implementing an event handler for the Exit
button

3.2. Implementing an event handler for the
Calculate button

2. Developing the View


Project name:
OrderCalculator


Class name:
OrderCalculatorView


Package:
ordercalculator


Frame title:
Order

Calculator


The Title Label


The Food and Drink Panel


The Bagel Panel


1 Button Group


The White Radio Button


The Whole wheat Radio Button


The Toppings Panel


4 Check Boxes


The Coffee Panel


1 Button Group


4 Radio Buttons


The Button Panel


2 Buttons


3.1. Implementing an event handler
for the Exit button


This is an exercise for you

3.2. Implementing an event handler
for the Calculate button

3.2.1. Declaring the
priceList

map and
implementing
initPriceList()

3.2.2. Implementing
getSubtotal()

3.2.3. Implementing the event handler

3.2.1. Declaring the
priceList

map and
implementing
initPriceList()


3.2.2. Implementing
getSubtotal()


3.2.3. Implementing the event handler


Exercise


Modify the application so that it has a
separate Model class

Solution

1.
The Design

2.
The View & Controller

3.
The Model

4.
The Data Transfer Object

1. The Design


Bill
- double subtotal
- double tax
- double total
<<Data Transfer Object>>
OrderCalculatorView
- OrderCalculator
<<View & Controller>>
OrderCalculator
<<Model>>
1
uses
uses
1
2. The View & Controller


3. The Model


4. The Data Transfer Object


References

1.
GUI Building in NetBeans IDE 5.5.
http://testwww.netbeans.org/kb/55/quicks
tart
-
gui.html

2.
Starting Out With Java 5 from control
structures to objects. Tony Gaddis