// DrawingDemoPanelApplet.java (c) Kari Laitinen // http://www.naturalprogramming.com/ // 2006-09-28 File created. // 2006-10-02 Last modification. // This program is another version of DrawingDemoApplet.java. // In this version a separate DrawingDemoPanel class is declared, and // a DrawingDemoPanel object contains the drawings that appear on the // screen. import java.awt.* ; import javax.swing.* ; class DrawingDemoPanel extends JPanel { int applet_width, applet_height ; public DrawingDemoPanel( int given_applet_width, int given_applet_height ) { applet_width = given_applet_width ; applet_height = given_applet_height ; } public void paintComponent( Graphics graphics ) { super.paintComponent( graphics ) ; graphics.drawString( "Applet area size is " + applet_width + " x " + applet_height, 20, 20 ) ; graphics.drawLine( 0, 100, 500, 100 ) ; graphics.drawLine( 0, 300, 500, 300 ) ; graphics.drawLine( applet_width / 2, 0, applet_width / 2, applet_height ) ; graphics.fillRect( 20, 50, 100, 40 ) ; graphics.fillRect( 20, 200, 100, 80 ) ; graphics.drawRect( 10, 190, 120, 100 ) ; graphics.copyArea( 10, 190, 120, 100, 150, 0 ) ; graphics.fillArc( 20, 350, 100, 80, 45, 270 ) ; graphics.fillArc( 170, 350, 100, 80, 315, 90 ) ; graphics.fillRect( 350, 50, 100, 40 ) ; graphics.clearRect( 360, 60, 80, 20 ) ; int[] polygon_coordinates_x = { 400, 450, 450, 400, 350, 350 } ; int[] polygon_coordinates_y = { 150, 180, 220, 250, 220, 180 } ; graphics.fillPolygon( polygon_coordinates_x, polygon_coordinates_y, 6 ) ; graphics.drawOval( 350, 350, 100, 80 ) ; graphics.drawRect( 350, 350, 100, 80 ) ; graphics.drawString( "X", 350, 350 ) ; } } public class DrawingDemoPanelApplet extends JApplet { public void init() { getContentPane().add( new DrawingDemoPanel( getSize().width, getSize().height ) ) ; } }