Scribble1public 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 |
Methods Summary |
---|
public boolean | action(java.awt.Event e, java.lang.Object arg)Respond to Button clicks
if (e.target == clear_button) {
clear();
return true;
}
else return false;
| public void | clear()convenience method to erase the scribble
g.setColor(this.getBackground());
g.fillRect(0, 0, bounds().width, bounds().height);
| public void | init()Initialize the button and the Graphics object
clear_button = new Button("Clear");
this.add(clear_button);
g = this.getGraphics();
| public boolean | keyDown(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 boolean | mouseDown(java.awt.Event e, int x, int y)Respond to mouse clicks
lastx = x; lasty = y;
return true;
| public boolean | mouseDrag(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;
|
|