FileDocCategorySizeDatePackage
Scribble.javaAPI DocExample2103Mon Oct 11 15:07:22 BST 1999None

Scribble

public class Scribble extends Applet
A simple applet using the Java 1.0 event handling model

Fields Summary
private int
lastx
private int
lasty
Button
erase_button
Graphics
g
Constructors Summary
Methods Summary
public booleanaction(java.awt.Event e, java.lang.Object arg)
Respond to Button clicks: erase drawing when user clicks button

    if (e.target == erase_button) {
      g.setColor(this.getBackground());   
      g.fillRect(0, 0, bounds().width, bounds().height);
      return true;
    }
    else return false;
  
public voidinit()
Initialize the button and the Graphics object

    erase_button = new Button("Erase");
    this.add(erase_button);
    g = this.getGraphics();
    this.requestFocus();  // Ask for keyboard focus so we get key events
  
public booleankeyDown(java.awt.Event e, int key)
Respond to key presses: Erase drawing when user types 'e'

    if ((e.id == Event.KEY_PRESS) && (key == 'e")) {
      g.setColor(this.getBackground());   
      g.fillRect(0, 0, bounds().width, bounds().height);
      return true;
    }
    else return false;
  
public booleanmouseDown(java.awt.Event e, int x, int y)
Respond to mouse clicks

    lastx = x; lasty = y;             // Remember where the click was
    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);   // Draw from last position to here
    lastx = x; lasty = y;             // And remember new last position
    return true;