Chapter 11 A GUI Interacting With a Problem Domain Class - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Chapter 11 A GUI Interacting With a Problem Domain Class

Description:

... allow a user to find a customer and then display their address and phone number ... JTextField objects are created to display the address and phone number ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 26
Provided by: johnf191
Category:

less

Transcript and Presenter's Notes

Title: Chapter 11 A GUI Interacting With a Problem Domain Class


1
Chapter 11A GUI Interacting With a Problem
Domain Class
11
2
Adding a New Customer
  • Develop a new GUI class named AddCustomer to
    input customer attribute values and then create
    instances of the Customer class

3
Adding a New Customer
4
Adding a New Customer
11
  • You need to start by importing the classes it
    uses
  • The java.awt class has the Font and Color classes
  • The javax.swing class contains the GUI components
  • The ActionEvent and ActionListener interfaces are
    in the java.awt.event class
  • JTextField instances are used to input the
    customers name, address, and phone number
  • JButton instances are used after the customer
    data is entered, to clear the text fields, and to
    end processing

5
Creating the Logo Panel
11
  • The JLabel class is used to contain the marinas
    logo
  • The foreground color is set to red using the
    Color.red constant
  • The font is set to Times Roman 36 point italic
    using the TimesRoman font name, and the
    Font.ITALIC constant

6
Creating the Center Panel
  • The customer name, address, and phone text boxes
    are added to the centerPanel
  • This panel is added to the Frame instance
  • The SwingConstants class is used to set the
    alignment
  • LEFT
  • RIGHT
  • CENTER

7
Creating the Lower Panel
11
  • Three button instances are added to the lower
    panel to support the Add, Clear, and Close
    operations
  • You need to call the addActionListener method for
    each button to process the events

8
Handling Events
  • An anonymous inner class is defined to handle
    events
  • The actionPerformed method determines which
    button was clicked, and then invokes the
    appropriate method to handle the event

9
Using a Dialog Box
11
  • If the user clicks the Add button, but hasnt
    entered valid data, an error message should be
    displayed
  • The statement to display a simple dialog box with
    a message that requires the user to click the OK
    button to continue isJOptionPane.showMessageDial
    og(this,message)

10
Using a Dialog Box
11
Using a Dialog Box
11
12
Finding a Customer
  • Sometimes you will need to search for a customer
    then display their information
  • The FindCustomer class will allow a user to find
    a customer and then display their address and
    phone number

13
Finding a Customer
11
14
Creating a Vector of Customers
11
  • Two vector variables are used to hold a list of
    customers and their names
  • The add method is used to add Customer objects to
    the vector

15
Using the JList Class
  • The JList class is used to display a list of
    customer names
  • When the user selects a name and then clicks on
    the Find button, that customers name and address
    are displayed
  • The JList constructor takes a Vector object which
    contains the data that is displayed

16
Adding Text Fields
  • JTextField objects are created to display the
    address and phone number
  • A JTextField object is used to allow the user to
    update these values

17
Adding a Boat
  • Develop a GUI that allows you to add a new boat
    to the marina system
  • You can add a PowerBoat or SailBoat

18
Adding a Boat
19
Adding a Boat
11
20
Adding a Boat
11
21
Adding a Boat
22
Using Radio Buttons
  • The radio buttons are used to indicate the type
    of boat you are adding
  • The RadioButton constructor takes two arguments
  • The caption to be displayed
  • The buttons initial state true if selected,
    false otherwise
  • You can trigger a radio button click event by
    calling doClick

23
Add A Sailboat
11
24
Add A PowerBoat
25
The clearForm Method
11
  • To blank out the text fields use the setText
    method pass an empty string as the argument
  • manufacturerText.setText()
Write a Comment
User Comments (0)
About PowerShow.com