Canvas

ALT= "Applet could not be loaded" Sorry, it is time to upgrade your browser to a Java powered one.


import java.applet.Applet;
import java.awt.*;

class NewCanvas extends Canvas {
	private int shape;

	public void paint (Graphics g)
	{
		if (shape == 1)
			g.fillOval (50, 10, 60, 60);
		else
			g.fillRect (50, 10, 60, 60);
	}
	public void setShape (int s)
	{
		shape = s;
		repaint();
	}
}

public class MyCanvas extends Applet {
	private Panel p;
	private NewCanvas c;
	private button circleButton, squareButton;
	
	public void init()
	{
		p = new Panel();
		c = new NewCanvas();
		
		c.resize (185, 125);
		
		squareButton = new Button( "Square");
		circleButton = new Button ("Circle");
		
		p.setLayout (new BorderLayout());
		p.add ("North", circleButton);
		p.add ("South", squareButton);
		
		setLayout (new BorderLayout());
		add ("West", p);
		add ("East", c);
	}
}