import java.applet.* ; import java.awt.* ; public class ExampleOfApplet extends Applet { int shape ; Button mybutton ; public void init() { shape = 0 ; mybutton = new Button("Next Shape") ; add(mybutton); } public void start() { } public void paint(Graphics g) { int x[] = {35, 150, 60, 140, 60, 150, 35}; int y[] = {50, 80, 110, 140, 170, 200, 230}; int xx[] = {50, 100, 150, 150, 100, 50 } ; int yy[] = {80, 40, 80, 130, 170, 130} ; g.setColor(Color.red); g.drawRect(10,10 , 400 , 230 ) ; g.drawString("Template of Applet" , 100 , 60 ) ; g.drawString("* 120 , 80 " , 120 , 80 ) ; g.drawString("* 140 , 100 " , 140 , 100 ) ; g.drawString("* 160 , 120 " , 160 , 120 ) ; g.drawString("* 180 , 140 " , 180 , 140 ) ; switch (shape) { case 0 : g.drawLine(10 , 20 , 100 , 150) ; g.drawString("g.drawLine" , 200, 160 ) ; break ; case 1 : g.drawRect(10 , 20 , 100 , 150) ; g.drawString("g.drawRect" , 200, 160 ) ; break ; case 2 : g.drawString("g.drawArc" , 200, 160 ) ; g.drawArc(35, 50, 125, 180, 90, 180) ; break ; case 3 : g.drawRoundRect(35, 50, 125, 180, 15, 15) ; g.drawString("g.drawRoundRect" , 200, 160 ) ; break ; case 4 : g.drawOval(10 , 20 , 100 , 150 ) ; g.drawString("g.drawOval" , 200, 160 ) ; break ; case 5 : g.drawPolygon(xx , yy , 6 ) ; g.drawString("g.drawPolygon 6 " , 200, 160 ) ; break ; case 6 : g.drawPolygon(x , y , 5 ) ; g.drawString("g.drawPolygon 5 " , 200, 160 ) ; break ; case 7 : g.fillRoundRect(40 , 40 , 120 , 170 , 20 , 20 ) ; g.drawString("g.fillRoundRect" , 200, 160 ) ; break ; } } public boolean action(Event event, Object arg) { ++shape; if (shape == 8) shape = 0; repaint(); return true; } public void stop() { } public void destroy() { } }