//
import java.awt.*;
public class Example5 extends BufferedApplet
{
int width = 0, height = 0, x, y;
int colorMode = 0;
boolean isClearingScreen = true;
public void render(Graphics g) {
if (width == 0) {
width = bounds().width;
height = bounds().height;
x = width / 2;
y = height / 2;
}
// DRAW A CLEAR WHITE BACKGROUND (MAYBE)
if (isClearingScreen) {
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
}
// DRAW A BLUE DISK AT x,y
g.setColor(colorMode == 0 ? Color.blue : Color.red);
g.fillOval(x - 20, y - 20, 40, 40);
}
public boolean keyUp(Event e, int key) {
switch (key) {
case ' ':
colorMode = 1 - colorMode;
break;
case '\n':
isClearingScreen = ! isClearingScreen;
break;
}
damage = true;
return true;
}
public boolean mouseDown(Event e, int x, int y) {
setXY(x, y);
return true;
}
public boolean mouseDrag(Event e, int x, int y) {
setXY(x, y);
return true;
}
void setXY(int x, int y) {
this.x = x;
this.y = y;
damage = true;
}
}