Java Programming Code Examples
Java > Java AWT Code Examples
Demonstrating method mouseDrag
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
33
34
35
36
37
38
39
40
41
42
43
44
Demonstrating method mouseDrag
import java.applet.Applet;
import java.awt.*;
public class Drag extends Applet {
private int xValue, yValue;
private boolean firstTime;
public void init()
{
// first running of program
firstTime = true;
}
public void paint( Graphics g )
{
// do not draw the first time
if ( !firstTime )
g.fillOval( xValue, yValue, 4, 4 );
}
// override Component class update
public void update( Graphics g )
{
// do not clear background
// only call paint
paint( g );
}
public boolean mouseDrag( Event e, int x, int y )
{
xValue = x;
yValue = y;
// enable drawing
firstTime = false;
repaint(); // call repaint
showStatus( "Event: mouseDrag" );
return true; // event handled
}
}