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;
}