Title: GUI Applications JList and JComboBox
1GUI ApplicationsJList and JComboBox
2Contents
- Problem The Photo Viewer
- New Requirement Replacing List Component By a
Combo Box - Problem The Fast Food Kiosk
- Exercise
3A. Problem The Photo Viewer
- Given five JPEG images pieDiagram.jpg,
lineGraph.jpg, barGraph.jpg, table.jpg, and
normalCurve.jpg, develop a GUI as shown in the
next slide
4(No Transcript)
5Solution
- Project name PhotoViewer
- Developing the View
- Preparing the images
- Implementing an event handler for the List
component - Setting the first item in the list to be selected
61. Developing the View
- Class name PhotoViewerView
- Package photoviewer
- Frame title Photo Viewer
- Label for the prompt
- List for the list of images
- model Pie Diagram, Line Graph, Bar Graph, Table,
Normal Curve - selectionMode SINGLE
- visibleRowCount 3
- Label for showing an image
- Label for the image title
7(No Transcript)
82. Preparing the images
- 2.1. Copying the images to the root folder
- 2.2. Declaring the images
93. Implementing an event handler for the List
component
- Right-click the List gt Events gt ListSelection gt
valueChanged
104. Setting the first item in the list to be
selected
11B. New Requirement Replacing List Component By a
Combo Box
12Solution
- Modifying the View
- Implementing an event handler for the Combo Box
- Showing the first image when the application is
started
131. Modifying the View
- The Combo Box
- model Pie Diagram, Line Graph, Bar Graph, Table,
Normal Curve - maximumRowCount 3
142. Implementing an event handler for the Combo Box
- Right-click the Combo Box gt Events gt Item gt
itemStateChanged
153. Showing the first image when the application
is started
16C. Problem The Fast Food Kiosk
- Develop an application that simulates a fast food
kiosk (See the next slide for an example) - The application displays a menu. The user makes a
selection and then presses a button. The
application then calculates and displays the bill - The tax rate is 6.5
17(No Transcript)
18Solution
- Project name FastFoodKiosk
- Developing the View
- Developing the Model
- Implementing an Event Handler for the Button
- Developing the Model
191. Developing the View
- Class name FastFoodKioskView
- Package fastfoodkiosk
- Frame title Welcome to Java Kiosk
- Label for the main title
- List for the fast food menu
- model Blueberry Muffins 0.85,
- selectionMode MULTIPLE
- visibleRowCount 11
- Text Area for the bill
- Button
202. Developing the Model
- 2.1. Finding the Main Task
- 2.2. Developing the Test Method
- 2.3. Developing Classes for the Model
212.1. Finding the Main Task
- Main task Calculate the bill of an order
222.2. Developing the Test Method
232.3. Developing Classes for the Model
24(No Transcript)
253. Implementing an Event Handler for the Button
- 3.1. Declaring the Model Inside the View
- 3.2. Showing the Bill
263.1. Declaring the Model Inside the View
273.2. Showing the Bill
28D. Exercise
- Modify the application so that when the button is
clicked the values of food items shown in the
JList component will be sent to the Model for
calculating the bill - Note In the current implementation, the indices
of food items are sent to the Model
29Solution
- Modifying the Event Handler
- Modifying the Model
301. Modifying the Event Handler
312. Modifying the Model
- 2.1. Making the Price List to Be a Map
- 2.2. Removing Data Duplication of Food Item Names
in the View and the Model
322.1. Making the Price List to Be a Map
332.2. Removing Data Duplication of Food Item Names
in the View and the Model
34References
- Java Programming. From Problem Analysis to
Program Design. Second Edition. D.S. Malik
35Revision History