GUI Panels and Color - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

GUI Panels and Color

Description:

Build telephone keypad. java8javaPanels&Color Lackey. 4. What is involved? ... Phone keypad. java8javaPanels&Color Lackey. 15. How? JPanel panel1 = new JPanel ... – PowerPoint PPT presentation

Number of Views:79
Avg rating:3.0/5.0
Slides: 20
Provided by: EdwardDon8
Category:
Tags: gui | color | keypad | magenta | panels

less

Transcript and Presenter's Notes

Title: GUI Panels and Color


1
GUI Panels and Color
2
Panels
  • A Panel is a portion of a Frame. A Panel is like
    a Frame within a Frame.
  • A panel can contain components ( buttons, text,
    etc.).
  • A panel can have its own Layout Manager
  • A panel can contain other panels.

3
Build telephone keypad
4
What is involved?
  • Build a Frame that will contain two panels.
  • The 1st panel will contain phone numbers.
  • This panel contains text.
  • The 2nd panel will contain the buttons.
  • This panel contains 12 buttons.

5
The basic solution.
  • Build the Frame.
  • Build the 1st panel.
  • Add the text to the panel.
  • Add the panel to the Frame.
  • Build the 2nd panel.
  • Add buttons.
  • Add panel to Frame.
  • Make visible.

6
The Detail
Should be easy !
7
The Frame
  • JFrame frameLackey
  • frameLackey new JFrame()
  • frameLackey.setSize(600,400)
  • frameLackey.setDefaultCloseOperation
  • (JFrame.EXIT_ON_CLOSE)

8
Setting up the Frame for two Panels
  • // 1st get the content of the Frame container
  • Container myContent frameLackey.getContentPan
    e()
  • // 2nd add the Layout Manager to the Frame
  • myContent.setLayout(new GridLayout(1,2))

9
Adding panels
  • // Build a panel
  • JPanel panel1 new JPanel()
  • // Add components to Panel
  • panel1.add(new JLabel("Internet Phone
    Directory"))
  • // add Panel to Frame
  • myContent.add(panel1)

10
Adding the second Panel
  • // Build a panel
  • JPanel panel2 new JPanel()
  • // Change LayoutManager (so 12 buttons can
    be added)
  • panel2.setLayout(new GridLayout(4,3))

11
Adding the Buttons
  • // Add components to Panel
  • for (int j 1jlt9j)
  • panel2.add(new JButton(""j))
  • panel2.add(new JButton(""))
  • panel2.add(new JButton("0"))
  • panel2.add(new JButton(""))
  • // add Panel to Frame
  • myContent.add(panel2)

12
Make visible
  • // make visible
  • frameLackey.setVisible(true)

13
More Color!
  • The class Color allows the selection of color for
    Foreground and Background. Color can be set for
    individual components.
  • The creator Color( red byte,
    greenbyte,bluebyte) void

14
Phone keypad
15
How?
  • JPanel panel1 new JPanel()
  • Color y new Color (200,0,0)
  • panel1.setBackground(y)

16
The next panel
  • JPanel panel2 new JPanel()
  • // Change LayoutManager
  • panel2.setLayout(new GridLayout(4,3))
  • // Add components to Panel
  • for (int j 1jlt9j)
  • panel2.add(new JButton(""j))
  • JButton x new JButton("")
  • x.setBackground(Color.GREEN)
  • panel2.add(x)
  • panel2.add(new JButton("0"))
  • panel2.add(new JButton(""))
  • // add Panel to Frame
  • myContent.add(panel2)

17
Color constants
  • Color.RED
  • Color.GREEN
  • Also BLACK, BLUE, CYAN,DARK_GRAY, GRAY,
    LIGHT_GRAY, MAGENTA,ORANGE, PINK, RED, WHITE,
    YELLOW,GREEN

18
Panel Summary
  • Panels
  • // Build a panel
  • JPanel panelName new JPanel()
  • // Add components to Panel
  • panelName.add( component1)
  • panelNnae.add( component2)
  • ..
  • // add Panel to Frame
  • myContent.add(panelName)

19
Panel Design Summary
  • Create a Frame
  • Set Layout Manager
  • While not done with panels
  • Create Panel
  • Set LayoutManager
  • Add components
  • Make visible

Isnt this course done?
Write a Comment
User Comments (0)
About PowerShow.com