GUI Applications JList and JComboBox - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

GUI Applications JList and JComboBox

Description:

Implementing an event handler for the List component ... model: Blueberry Muffins 0.85, ... selectionMode: MULTIPLE. visibleRowCount: 11 ... – PowerPoint PPT presentation

Number of Views:432
Avg rating:3.0/5.0
Slides: 36
Provided by: saigont
Category:

less

Transcript and Presenter's Notes

Title: GUI Applications JList and JComboBox


1
GUI ApplicationsJList and JComboBox
2
Contents
  • Problem The Photo Viewer
  • New Requirement Replacing List Component By a
    Combo Box
  • Problem The Fast Food Kiosk
  • Exercise

3
A. 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)
5
Solution
  • 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

6
1. 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)
8
2. Preparing the images
  • 2.1. Copying the images to the root folder
  • 2.2. Declaring the images

9
3. Implementing an event handler for the List
component
  • Right-click the List gt Events gt ListSelection gt
    valueChanged

10
4. Setting the first item in the list to be
selected
11
B. New Requirement Replacing List Component By a
Combo Box
12
Solution
  • Modifying the View
  • Implementing an event handler for the Combo Box
  • Showing the first image when the application is
    started

13
1. Modifying the View
  • The Combo Box
  • model Pie Diagram, Line Graph, Bar Graph, Table,
    Normal Curve
  • maximumRowCount 3

14
2. Implementing an event handler for the Combo Box
  • Right-click the Combo Box gt Events gt Item gt
    itemStateChanged

15
3. Showing the first image when the application
is started
16
C. 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)
18
Solution
  • Project name FastFoodKiosk
  • Developing the View
  • Developing the Model
  • Implementing an Event Handler for the Button
  • Developing the Model

19
1. 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

20
2. Developing the Model
  • 2.1. Finding the Main Task
  • 2.2. Developing the Test Method
  • 2.3. Developing Classes for the Model

21
2.1. Finding the Main Task
  • Main task Calculate the bill of an order

22
2.2. Developing the Test Method
23
2.3. Developing Classes for the Model
24
(No Transcript)
25
3. Implementing an Event Handler for the Button
  • 3.1. Declaring the Model Inside the View
  • 3.2. Showing the Bill

26
3.1. Declaring the Model Inside the View
27
3.2. Showing the Bill
28
D. 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

29
Solution
  • Modifying the Event Handler
  • Modifying the Model

30
1. Modifying the Event Handler
31
2. 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

32
2.1. Making the Price List to Be a Map
33
2.2. Removing Data Duplication of Food Item Names
in the View and the Model
34
References
  • Java Programming. From Problem Analysis to
    Program Design. Second Edition. D.S. Malik

35
Revision History
Write a Comment
User Comments (0)
About PowerShow.com