<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.awt.*;
import awb.*;
import java.awt.event.*;

public class GDemo extends java.applet.Applet
                    implements ActionListener
// A demonstration program for the Graphics methods drawLine,
// drawOval, and darwRect.
{
     Graphics g;
     Canvas c;
     Button b1, b2, b3, b4;

     public void init()
     {
         c = new Canvas();
         c.setSize(200,200); // Set the size of the Canvas.
         add(c);
         g = c.getGraphics(); // Get the Graphics object from c.
         b1 = new Button("Start");
         b1.addActionListener(this);
         b2 = new Button("Line");
         b2.addActionListener(this);
         b3 = new Button("Oval");
         b3.addActionListener(this);
         b4 = new Button("Rectangle");
         b4.addActionListener(this);
         add(b1); add(b2); add(b3); add(b4);
     }

     public void actionPerformed(ActionEvent event)
     {
        Object cause = event.getSource();

        if (cause == b1)
	{
           g.setColor(Color.white);
           // Color the whole cnavas white.
           g.fillRect(0, 0, 200, 200);
        }
        if (cause == b2)
	{
           g.setColor(Color.blue);
           g.drawLine(50, 50, 150, 100); // Demonstrate drawLine.
        }
        if (cause == b3)
        {
           g.setColor(Color.green);
           g.drawOval(50,50,100,50); // Demonstrate drawOval.
        }
        if (cause == b4)
	{
           g.setColor(Color.red);
           g.drawRect(50, 100, 100, 50); // Demonstrate drawRect.
        }
     }
}
</pre></body></html>