FileDocCategorySizeDatePackage
Scribble1.javaAPI DocExample1742Wed Jun 03 10:32:36 BST 1998None

Scribble1

public class Scribble1 extends Applet
A simple applet that uses the Java 1.0 event handling model

Fields Summary
private int
lastx
private int
lasty
Button
clear_button
Graphics
g
Constructors Summary
Methods Summary
public booleanaction(java.awt.Event e, java.lang.Object arg)
Respond to Button clicks

    if (e.target == clear_button) {
      clear();
      return true;
    }
    else return false;
  
public voidclear()
convenience method to erase the scribble

    g.setColor(this.getBackground());
    g.fillRect(0, 0, bounds().width, bounds().height);
  
public voidinit()
Initialize the button and the Graphics object

    clear_button = new Button("Clear");
    this.add(clear_button);
    g = this.getGraphics();
  
public booleankeyDown(java.awt.Event e, int key)
Respond to key presses

    if ((e.id == Event.KEY_PRESS) && (key == 'c")) {
      clear();
      return true;
    }
    else return false;
  
public booleanmouseDown(java.awt.Event e, int x, int y)
Respond to mouse clicks

    lastx = x; lasty = y;
    return true;
  
public booleanmouseDrag(java.awt.Event e, int x, int y)
Respond to mouse drags

    g.setColor(Color.black);
    g.drawLine(lastx, lasty, x, y);
    lastx = x; lasty = y;
    return true;