import java.awt.Graphics.
import java.awt.Event.
import java.awt.Color.
public class mouse extends java.applet.Applet
{
int num=0.//计数器初始化
int px,py.
public boolean mouseDown(Event evt,int x,int y)//鼠标按下事件
{
px=x.
py=y.//鼠标按下时的坐标
num .//计数器加1
repaint().//重画窗口
return true.//返回true,表示事件处理过了
}
public void 0update(Graphics g)
{
g.setColor(getBackground()).//以背景色取出一快区域
g.fillRect(10,300,200,60).
paint(g).//调用paint方法
}
public void paint(Graphics g)
{
g.setColor(Color.green).
g.drawString("当前鼠标的坐标是(" px "," py ")",10,300).//输出当前鼠标的坐标
g.drawString("This is No." num "point",10,340).//输出点击次数
g.setColor(Color.red).//在鼠标点击位置画出一个红叉
g.drawLine(px-5,py-5,px 5,py 5).
g.drawLine(px 5,py-5,px-5,py 5).
}
}
111
>
|