package other;import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;public class MyMouseMotionEvent extends Applet implements MouseMotionListener{
int y=-1;
int x=-1;
public void init()
{
setBackground(Color.green);
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e)
{
x=e.getX();
y=e.getY();
repaint();
}
public void update(Graphics g)//这个函数是用背景色消除画面,然后再调用paint吗?如果是只调用了paint?如果不是的话,是怎样达到重绘效果的?
{
paint(g);
}

public void paint(Graphics g)
{
if(x!=-1&&y!=-1)
{
g.setColor(Color.red);
g.fillOval(x, y, 3, 3);
}
}
public void mouseMoved(MouseEvent e)
{

}}