// DrawingDemoAWTApplet.java (c) 2006 Kari Laitinen // http://www.naturalprogramming.com/ // 2006-09-28 File created. // 2006-09-28 Last modification. // This is a 'traditional' AWT version of DrawingDemoApplet.java // This program demonstrates the drawing methods provided in // the Graphics class. A Graphics object is given as a parameter // for the paint() method. The paint() method is called automatically // by the program execution system whenever there is a need to // update the applet area on the screen. // The init() method is called once when the applet starts executing. import java.awt.* ; public class DrawingDemoAWTApplet extends java.applet.Applet { int applet_width, applet_height ; public void init() { applet_width = getSize().width ; applet_height = getSize().height ; } public void paint( Graphics 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 ) ; } }