Chapter 14 Using Layout Managers - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Chapter 14 Using Layout Managers

Description:

When the user selects a name and then clicks on the Find button, that customer's ... Find Customer GUI (ii) Chapter 11 - A GUI Interacting With a Problem Domain Class ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 35
Provided by: johnf190
Category:

less

Transcript and Presenter's Notes

Title: Chapter 14 Using Layout Managers


1
Chapter 14Using Layout Managers
11
2
Adding a New Customer
3
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

4
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

5
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

6
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

7
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

8
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)

9
Using a Dialog Box
10
Using a Dialog Box
11
11
Add Customer GUI (i)
12
Add Customer GUI (ii)
13
Add Customer GUI (iii)
14
Finding a Customer
11
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
Find Customer GUI (i)
18
Find Customer GUI (ii)
19
Find Customer GUI (iii)
20
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

21
Adding a Boat
22
Adding a Boat
11
23
Adding a Boat
11
24
Adding a Boat
25
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

26
Add A Sailboat
11
27
Add A PowerBoat
28
The clearForm Method
11
  • To blank out the text fields use the setText
    method pass an empty string as the argument
  • manufacturerText.setText()

29
AddBoat.java (i)
30
AddBoat.java (ii)
31
AddBoat.java (iii)
32
AddBoat.java (iv)
33
AddBoat.java (v)
34
AddBoat.java (vi)
Write a Comment
User Comments (0)
About PowerShow.com