import awb.*; import java.awt.*; import java.awt.event.*; public class GDemo2 extends java.applet.Applet implements ActionListener // A demonstration program for the Graphics methods drawLine, drawOval, // and drawRect. { Graphics g; Canvas c; IntField iX, iY; Button b1, b2, b3, b4, b5; int x, y; public void init() { c = new Canvas(); c.setSize(200, 200); add(c); g = c.getGraphics(); b1 = new Button("Start"); b2 = new Button("Oval"); b3 = new Button("Rectangle"); b4 = new Button("SetCorner"); b5 = new Button("Shift"); iX = new IntField(20); iY = new IntField(20); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); add(iX); add(iY); add(b1); add(b2); add(b3); add(b4); add(b5); } public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); if (cause == b1) { g.setColor(Color.white); // Color the whole canvas white g.fillRect(0, 0, 200, 200); } if (cause == b2) { g.setColor(Color.green); g.drawOval(x, y, 100, 50); // Demonstrate drawOval } if (cause == b3) { g.setColor(Color.red); g.drawRect(x, y, 100, 50); // Demonstrate drawRect } if (cause == b4) { x = iX.getInt(); y = iY.getInt(); } if (cause == b5) { x = x + 5; y = y + 5; } } }