//
import java.applet.*;
import java.awt.*;
public class Doodle extends Applet {
private int last_x = 0, last_y = 0; // variable to retain last known position
private int[] x_arr,y_arr; // arrays to retain drawing points
private boolean[] drag; // array to indicate if line should connect points
private int cntr=0; // count of total points established
// Constructor (invoked to create instance)
public Doodle() {
x_arr = new int[1024]; // create arrays
y_arr = new int[1024];
drag = new boolean[1024];
}
// mouse button depressed
public boolean mouseDown(Event e, int x, int y) {
Store(x,y,false); // Store co-ordinates (do not connect line)
last_x = x;
last_y = y;
return true;
}
// mouse button released
public boolean mouseUp(Event e, int x, int y) {
Store(x,y,false); // Store co-ordinates (do not connect line)
return true;
}
// mouse moved while mouse button depressed
public boolean mouseDrag(Event e, int x, int y) {
Store(x,y,true); // Store co-ordinates (connect line)
Graphics g = getGraphics();
g.drawLine(last_x,last_y, x,y);
last_x = x;
last_y = y;
return true;
}
// paint method (called by browser when screen needs to be redrawn)
public void paint(Graphics g) {
int counter, stored_x = x_arr[0], stored_y = y_arr[0];
for(counter=1; counter-->