Download presentation
Presentation is loading. Please wait.
1
Lecture 16: GUI programming JFrame windows (p.247) Containers and layout managers (p.290) Inheriting GUI components (p.330) Chapter 12: GUI programming Skip Chapters 10 and 11 for now but will return to them soon
2
JFrame Windows (p.247) All JXxxx classes are part of swing JFrame extends Frame (in awt) Frame extends Window Window extends Container Container extends Component Component extends Object
3
JFrame methods JFrame frame1 = new JFrame(); frame1.setTitle(“Window 1”); frame1.setSize(200,150); frame1.setLocation(200,100); frame1.setDefaultCloseOperation(JFram e.EXIT_ON_CLOSE);
4
Containers and Layout Managers (p.290) We can add various components to a frame window, such as buttons JButton yesButton = new JButton(“yes”); frame1.add(yesButton); frame1.setVisible; JButton noButton = new JButton(“no”); frame1.add(noButton); frame1.setVisible() The “no” button overwrote the “yes” button. To avoid that we use FlowLayout
5
FlowLayout FlowLayout layout = new FlowLayout(); frame1.setLayout(layout) these lines go before you start adding components after adding components, need to call setVisible
6
Inheriting GUI components (p.330) Suppose we want to design a frame window and then construct multiple instances of it public class OurFrame extends JFrame{ –public OurFrame() { –…–… –}–} Then we can construct multiple instances of OurFrame
7
Chapter 12: more details Container classes (JFrame, JPanel, JApplet, etc) Component classes (JButton, JLabel, JTextField, JCheckBox, JRadioButton, JComboBox, JMenu, etc) Helper classes (FlowLayout, GridLayout, Color, Font, Graphics, etc
8
GridLayout and Color Gridlayout layout = new GridLayout(5,3); –specifies horizontal and vertical grid Color color = new Color(128,128,128) –specifies red, green, blue –button.setBackground(color); –button.setForeground(color); –random colors
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.