Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved 8.3.2 More About the Standard Drawing Classes java.awt.Container.

Similar presentations


Presentation on theme: "Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved 8.3.2 More About the Standard Drawing Classes java.awt.Container."— Presentation transcript:

1 Lecture 8.3 The Use of JComponent

2 © 2006 Pearson Addison-Wesley. All rights reserved 8.3.2 More About the Standard Drawing Classes java.awt.Container «constructor» + Container() «update» + void add( Component, int ) + void remove( Component, int ) + void repaint() + void setBackground( Color ) + void setForeground( Color ) + void setBounds( int, int, int, int ) + void setLocation( int, int ) + void setSize( int, int ) «query» + int getX() + int getY() + int getWidth() + int getHeight() + Color getBackground() + Color getForeground()... javax.swing.JComponent «constructor» + JComponent() «update» + void paint( Graphics ) + void paintChildren( Graphics )

3 © 2006 Pearson Addison-Wesley. All rights reserved 8.3.3 The paint Method javax.swing.JComponent «constructor» + JComponent() «update» + void paint( Graphics ) + void paintChildren( Graphics ) paint is called automatically by the JVM in order to draw the JComponent. You build your own drawing object by inheriting JComponent and overriding paint. import java.awt.*; import javax.swing.JComponent; public class Oval extends JComponent { public Oval( int x, int y, int w, int h ) { super(); setBounds(x, y, w, h); setBackground( Color.black ); } public void paint( Graphics g ) { g.setColor( getBackground() ); g.fillOval(0, 0, getWidth()-1, getHeight()-1); paintChildren(g); } import java.awt.*; import javax.swing.JComponent; public class Oval extends JComponent { public Oval( int x, int y, int w, int h ) { super(); setBounds(x, y, w, h); setBackground( Color.black ); } public void paint( Graphics g ) { g.setColor( getBackground() ); g.fillOval(0, 0, getWidth()-1, getHeight()-1); paintChildren(g); }

4 © 2006 Pearson Addison-Wesley. All rights reserved 8.3.4 java.awt.Graphics «update» + void drawLine( int x1, int y1, int x2, int y2 ) + void drawOval( int x, int y, int w, int h ) + void drawRect( int x, int y, int w, int h ) + void drawString( String s ) + void fillOval( int x, int y, int w, int h ) + void fillRect( int x, int y, int w, int h ) + void fillString( String s ) + void setColor( Color c )... java.awt.Graphics «update» + void drawLine( int x1, int y1, int x2, int y2 ) + void drawOval( int x, int y, int w, int h ) + void drawRect( int x, int y, int w, int h ) + void drawString( String s ) + void fillOval( int x, int y, int w, int h ) + void fillRect( int x, int y, int w, int h ) + void fillString( String s ) + void setColor( Color c )... The Standard Graphics Class


Download ppt "Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved 8.3.2 More About the Standard Drawing Classes java.awt.Container."

Similar presentations


Ads by Google