FileDocCategorySizeDatePackage
Scribble6.javaAPI DocExample2121Sat Jun 02 02:43:28 BST 2001None

Scribble6

public class Scribble6 extends Applet
A simple applet that uses low-level event handling under Java 1.1

Fields Summary
private int
lastx
private int
lasty
Constructors Summary
Methods Summary
public voidinit()
Tell the system we're interested in mouse events, mouse motion events, and keyboard events. This is a required or events won't be sent.

    this.enableEvents(AWTEvent.MOUSE_EVENT_MASK |
                      AWTEvent.MOUSE_MOTION_EVENT_MASK |
                      AWTEvent.KEY_EVENT_MASK);
    this.requestFocus();  // Ask for keyboard focus so we get key events
  
public voidprocessKeyEvent(java.awt.event.KeyEvent e)
Called on key events: clear the screen when 'c' is typed

    if ((e.getID() == KeyEvent.KEY_TYPED) && (e.getKeyChar() == 'c")) {
      Graphics g = this.getGraphics();
      g.setColor(this.getBackground());
      g.fillRect(0, 0, this.getSize().width, this.getSize().height);
    }
    else super.processKeyEvent(e);  // pass unhandled events to our superclass
  
public voidprocessMouseEvent(java.awt.event.MouseEvent e)
Invoked when a mouse event of some type occurs

    if (e.getID() == MouseEvent.MOUSE_PRESSED) {  // check the event type
      lastx = e.getX(); lasty = e.getY();
    }
    else super.processMouseEvent(e); // pass unhandled events to our superclass
  
public voidprocessMouseMotionEvent(java.awt.event.MouseEvent e)
Invoked when a mouse motion event occurs

    if (e.getID() == MouseEvent.MOUSE_DRAGGED) {  // check type
      int x = e.getX(), y = e.getY();
      Graphics g = this.getGraphics();
      g.drawLine(lastx, lasty, x, y);
      lastx = x; lasty = y;
    }
    else super.processMouseMotionEvent(e);