package mypackage;
import java.awt.*;
import java.lang.*;
import java.awt.event.*;public class MousemotionFrame extends Frame
{
private MousemotionFrame F;
private Label dragobj;
private int orix,oriy;   
private int oldx,oldy;  
private int X,Y;
public MousemotionFrame()
{
F=this;
this.setLayout(null);
this.setBounds(300,100,280,200);
dragobj=new Label("板擦");
dragobj.setBounds(20,30,50,30);
dragobj.setBackground(Color.RED);
dragobj.addMouseMotionListener(new myMouseMotionListener());
this.add(dragobj);
this.addMouseMotionListener(new myMouseMotionListener());
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}

public void windowIconified(WindowEvent e)
{
F.setTitle("最小化");
}
//问题一:
/*匿名类继承父类WindowAdapter,在子类的windowIconified()方法中
添加了将窗口名字改为“最小化”的语句.为什么运行时窗口依然能够最小化?
如果按照子类的方法覆盖父类的同名方法的话,那么运行时是不能将窗口最小
化掉的,另外我注意到父类WindowAdapter中的windowIconified()方法
的{}是空的,这应该是特意的做法。但道理是什么?跟覆盖是否冲突?*/

});
this.setVisible(true);

}

public void update(Graphics g)
{
g.drawLine(oldx,oldy,X,Y);
}

class myMouseMotionListener implements MouseMotionListener
{
public void mouseMoved(MouseEvent e)
{
if(e.getComponent()==F)
{
X=e.getX();
Y=e.getY();
F.setTitle("小白板与板擦 MOVED X= "+X+"Y="+Y);
}
}

public void mouseDragged(MouseEvent e)
{
if(e.getComponent()==F)
{
oldx=X;
oldy=Y;
X=e.getX();
Y=e.getY();
F.repaint();
F.setTitle("小白板与板擦 MOVED X= "+X+"Y="+Y);
}
else
{
//问题二:
/*为什么板擦轨迹经过的地方的点都被“擦”掉了?
看代码中只是将板擦的位置发生改变了而已,并
没有去删除轨迹上的点,那么这些点是怎么消失的?*/
X=e.getX();
Y=e.getY();
dragobj.setLocation(dragobj.getLocation().x+(X-orix),
dragobj.getLocation().y+(Y-oriy));


}
}
}

public static void main(String arg[])
{
new MousemotionFrame();
}
//问题三:
为什么每次当我把窗口最小化或者还原操作时,作图痕迹变没有了,要怎么
杨才可以保留了??