ch18 - Chapter Eighteen: Graphical User Interfaces Chapter...

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

View Full Document Right Arrow Icon
Chapter Eighteen: Graphical User Interfaces
Background image of page 1

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

View Full DocumentRight Arrow Icon
Chapter Goals To understand the use of layout managers to arrange user- interface components in a container To become familiar with common user-interface components, such as buttons, combo boxes, text areas, and menus To build programs that handle events from user-interface components To learn how to browse the Java documentation
Background image of page 2
Layout Management Up to now, we have had limited control over layout of components When we used a panel, it arranged the components from the left to the right User-interface components are arranged by placing them inside containers Containers can be placed inside larger containers Each container has a layout manager that directs the arrangement of its components Three useful layout managers: border layout flow layout grid layout
Background image of page 3

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

View Full DocumentRight Arrow Icon
Layout Management By default, JPanel places components from left to right and starts a new row when needed Panel layout carried out by FlowLayout layout manager Can set other layout managers panel.setLayout(new BorderLayout());
Background image of page 4
Border Layout Border layout groups container into five areas: center, north, west, south and east
Background image of page 5

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

View Full DocumentRight Arrow Icon
Border Layout Default layout manager for a frame (technically, the frame's content pane) When adding a component, specify the position like this: panel.add(component, BorderLayout.NORTH); Expands each component to fill the entire allotted area If that is not desirable, place each component inside a panel
Background image of page 6
Grid Layout Arranges components in a grid with a fixed number of rows and columns Resizes each component so that they all have same size Expands each component to fill the entire allotted area Add the components, row by row, left to right: JPanel numberPanel = new JPanel(); numberPanel.setLayout(new GridLayout(4, 3)); numberPanel.add(button7); numberPanel.add(button8); numberPanel.add(button9); numberPanel.add(button4); . . . Continued
Background image of page 7

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

View Full DocumentRight Arrow Icon
Grid Layout
Background image of page 8
Grid Bag Layout Tabular arrangement of components Columns can have different sizes Components can span multiple columns Quite complex to use Not covered in the book Fortunately, you can create acceptable-looking layouts by nesting panels Give each panel an appropriate layout manager Panels don't have visible borders Use as many panels as needed to organize components
Background image of page 9

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

View Full DocumentRight Arrow Icon
Nesting Panels Example Keypad from the ATM GUI in Chapter 12: JPanel keypadPanel = new JPanel(); keypadPanel.setLayout(new BorderLayout()); buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(4, 3)); buttonPanel.add(button7); buttonPanel.add(button8); // . . . keypadPanel.add(buttonPanel, BorderLayout.CENTER); JTextField display = new JTextField(); keypadPanel.add(display, BorderLayout.NORTH); Continued
Background image of page 10
Nesting Panels Example (cont.)
Background image of page 11

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

View Full DocumentRight Arrow Icon
How do you add two buttons to the north area of a frame? Answer:
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.

This note was uploaded on 02/27/2009 for the course SC 418262 taught by Professor Chuleerut during the Spring '08 term at Kasetsart University.

Page1 / 77

ch18 - Chapter Eighteen: Graphical User Interfaces Chapter...

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