1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import java.applet.*;
import java.awt.*;
public class mouseEvent extends Applet {
int xpoint, ypoint;
public boolean mouseDown(Event evt, int x, int y) {
xpoint = x;
ypoint = y;
return true;
}
public boolean mouseDrag(Event evt, int x, int y) {
Graphics g = getGraphics();
g.setColor(Color.green);
g.drawLine(xpoint, ypoint, x, y);
xpoint = x;
ypoint = y;
return true;
}
public static void main (String [] args) {
int x, y;
Event evt = new Event();
mouseEvent msevt = new mouseEvent();
if(msevt.mouseDown(evt, x, y))
{
msevt.mouseDrag(evt, x, y);
}
}
} |
Partager