import java.awt.*; public class DrawingCanvas extends Canvas { private int x = 20, y = 20; private int width = 10, height = 10; private int inc = 5; private Color myColor = Color.red; private String object = "Rectangle"; public DrawingCanvas() { setBackground(Color.green); } public void paint(Graphics g) { g.setColor(Color.black); g.drawRect(0,0,size().width, size().height); g.setColor(myColor); if (object.equals("Rectangle")) g.fillRect(x,y,width,height); if (object.equals("Circle")) g.fillOval(x,y,width, height); if (object.equals("Oval")) g.fillOval(x,y, width, 2*height); } // private methods public boolean handleUp() { if (y > 0) y = y - inc; else y = size().height; repaint(); return true; } public boolean handleDown() { if (y < size().height) y = y + inc; else y = 0; repaint(); return true; } public boolean handleRight() { if (x < size().width) x = x + inc; else x = 0; repaint(); return true; } public boolean handleLeft() { if (x > 0) x = x - inc; else x = size().width; repaint(); return true; } public boolean handleIncrease() { width += 5; height += 5; repaint(); return true; } public boolean handleDecrease() { if (width > 5) { width -= 5; height -= 5; } repaint(); return true; } public boolean handleChangeObject(String s) { object = s; repaint(); return true; } public boolean handleColorChange(Color color) { myColor = color; repaint(); return true; } }