lecture16

lecture16 - PIC 20A Lecture 16: JFrames, JComponents, and...

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

View Full Document Right Arrow Icon
PIC 20A Lecture 16: JFrames, JComponents, and Graphics
Background image of page 1

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

View Full DocumentRight Arrow Icon
What is a JFrame? • a window with a title bar •A content pane is a container that holds and displays swing GUI components ( JComponent s) according to some layout .
Background image of page 2
What a JFrame looks like title bar content pane is the gray panel
Background image of page 3

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

View Full DocumentRight Arrow Icon
How do I make a JFrame? 1. Construct a JFrame object JFrame f = new JFrame(); 2. Set its size f.setSize(width, height); 3. Set the title (if not in the constructor call) f.setTitle(“Example JFrame”); 4. Set the default close operation f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 5. Make the JFrame visible f.setVisible(true);
Background image of page 4
Drawing Shapes • extend the JComponent class to define a shape or figure to draw on a JFrame ’s content pane • to explain how to paint your object, override the following method inherited from JComponent public void paintComponent(Graphics g){ // use g to draw your figure } This is called every time the JComponent needs to be repainted.
Background image of page 5

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

View Full DocumentRight Arrow Icon
paintComponent called? • when the
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

lecture16 - PIC 20A Lecture 16: JFrames, JComponents, and...

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

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