ch14 - Java Programming Fourth Edition Chapter 14 Using...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Programming Fourth Edition Chapter 14 Using Layout Managers and Events
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 2 Objectives • Learn about layout managers • Use JPanels to increase layout options • Understand events and event handling • Use the AWTEvent class methods • Handle mouse events
Background image of page 2
Java Programming, Fourth Edition 3 Learning About Layout Managers • Layout manager – Controls size and position of Components inside a Container object – Assign to content pane or panel – Interface classes – Part of Java SDK – Align components so that they don’t: • Crowd each other • Overlap
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 4 Learning About Layout Managers (continued) • Layout manager (continued) – Arrange components within a Container – Container can also be Container itself – Assign layout managers within layout managers • Java platform-supplied layout managers – FlowLayout and GridLayout – BorderLayout and CardLayout – GridBagLayout and BoxLayout
Background image of page 4
Java Programming, Fourth Edition 5 Java Layout Managers
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 6 Using BorderLayout • BorderLayout manager – Default for all content panes – Use with: • Container with five or fewer components • Component containers can hold more components – Fill screen in regions • North • South • East • West • Center
Background image of page 6
Java Programming, Fourth Edition 7 The JDemoBorderLayout Application
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 8 Using BorderLayout (continued) • Static import feature – Allows static constant without class name import static java.awt.BorderLayout.*; • GUI component must be part of: – Containment hierarchy • Tree of components • Top-level container as its root
Background image of page 8
Java Programming, Fourth Edition 9 Using BorderLayout (continued) • Create Container named con – Set layout manager to BorderLayout con.setLayout(new BorderLayout()); • To set layout manager setLayout(new BorderLayout()); Or this.setLayout(new BorderLayout()); • Place object in south region of JApplet’ s Container add(someButton, BorderLayout.SOUTH)
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 10 Using FlowLayout • FlowLayout manager – Arrange components in rows across width of Container – Add Component • Place to right of previously added components in row • If current row filled Component placed to start new row – Each Component retains preferred size
Background image of page 10
Java Programming, Fourth Edition 11 Using FlowLayout (continued) • Align Components with Container FlowLayout.LEFT FlowLayout.CENTER FlowLayout.RIGHT – If alignment not specified • Components center-aligned
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Programming, Fourth Edition 12 The JDemoFlowLayout Applet
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 44

ch14 - Java Programming Fourth Edition Chapter 14 Using...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online