GUIs - Part 2 (12)

GUIs - Part 2 (12) - COP 3330: GUIs In Java Part 2 Page 1...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COP 3330: GUIs In Java Part 2 Page 1 Dr. Mark Llewellyn COP 3330: Object-Oriented Programming Summer 2011 Introduction To GUIs and Event-Driven Programming In Java Part 2 Department of Electrical Engineering and Computer Science Computer Science Division University of Central Florida Instructor : Dr. Mark Llewellyn markl@cs.ucf.edu HEC 236, 407-823-2790 http://www.cs.ucf.edu/courses/cop3330/sum2011 COP 3330: GUIs In Java Part 2 Page 2 Dr. Mark Llewellyn Using Panels as Subcontainers Suppose that you want to place ten buttons and a text field in a frame. The buttons are placed in a grid formation, but the text field is to be placed on a separate row. It would be difficult to achieve this effect by placing all of the components into a single container. With Java GUI programming, you can divide a window into panels. Panels act as subcontainers to group user-interface components. We can then add the buttons to one panel and then add the panel into the frame. The Swing version of panel is JPanel . You can use new JPanel() to create a panel with a default FlowLayout manager or new JPanel(LayoutManager) to create a panel with the specified layout manager. The following example illustrates using panels as subcontainers. COP 3330: GUIs In Java Part 2 Page 3 Dr. Mark Llewellyn Example Using Panels COP 3330: GUIs In Java Part 2 Page 4 Dr. Mark Llewellyn The program uses panel p1 ( GridLayout manager) to group the number buttons, the Start button, and the Stop button, and panel p2 ( BorderLayout manager) to hold a text field in the north and the panel p1 in the center. The button representing the food is placed in the center of the frame, and p2 is placed in the east of the frame. See pages 6 and 7. COP 3330: GUIs In Java Part 2 Page 5 Dr. Mark Llewellyn JButton JFrame JPanel p2 JPanel p1 COP 3330: GUIs In Java Part 2 Page 6 Dr. Mark Llewellyn Initial frame no components added yet. Showing just panel p1 added to the frame. COP 3330: GUIs In Java Part 2 Page 7 Dr. Mark Llewellyn Showing panel p2 added to the frame panel p2 uses a BorderLayout with the JTextField placed in the North area and panel p1 placed in the Center area. Other areas on the BorderLayout are not used. Showing final frame using BorderLayout . Added a JButton (Food to be placed here) to the Center area. Added panel p2 to the East area. A button A textfield 12 buttons frame p2 p1 COP 3330: GUIs In Java Part 2 Page 8 Dr. Mark Llewellyn Common Features of Swing GUI Components Weve already used several GUI components (e.g., JFrame, Container, JPanel, JButton, JLabel, JTextField ) in the previous example....
View Full Document

Page1 / 67

GUIs - Part 2 (12) - COP 3330: GUIs In Java Part 2 Page 1...

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

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