FileDocCategorySizeDatePackage
Scribble7.javaAPI DocExample1811Mon Sep 22 13:30:30 BST 1997None

Scribble7

public class Scribble7 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()
Specify the event types we care about, and ask for keyboard focus

    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 voidprocessEvent(java.awt.AWTEvent e)
Called when an event arrives. Do the right thing based on the event type. Pass unhandled events to the superclass for possible processing

    MouseEvent me;
    Graphics g;
    switch(e.getID()) {
    case MouseEvent.MOUSE_PRESSED:
      me = (MouseEvent)e;
      lastx = me.getX(); lasty = me.getY();
      break;
    case MouseEvent.MOUSE_DRAGGED:
      me = (MouseEvent)e;
      int x = me.getX(), y = me.getY();
      g = this.getGraphics();
      g.drawLine(lastx, lasty, x, y);
      lastx = x; lasty = y;
      break;
    case KeyEvent.KEY_TYPED:
      if (((KeyEvent)e).getKeyChar() == 'c") {
        g = this.getGraphics();
        g.setColor(this.getBackground());
        g.fillRect(0, 0, this.getSize().width, this.getSize().height);
      }
      else super.processEvent(e);
      break;
    default: super.processEvent(e); break;
    }