import java.awt.*;
import java.awt.event.*;
class MyButton extends Button
{
private MyButton friend;
public void setfriend(MyButton friend)
{
this.friend=friend;
}
public MyButton(String name)
{
super(name);
enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
}
protected void processMouseMotionEvent(MouseEvent e)
{
setVisible(false);
friend.setVisible(true);
}
}
public class TestMyButton
{
public static void main(String args[])
{
MyButton btn1=new MyButton("你来抓我呀");
MyButton btn2=new MyButton("你来抓我呀");
btn1.setfriend(btn2);
btn2.setfriend(btn1);
btn1.setVisible(true);
Frame f=new Frame("it315");
f.setBackground(Color.red);
f.addWindowListener(new MyWindowlistenter());
f.add(btn1,"North");
f.add(btn2,"South");
f.setSize(300,300);
f.setVisible(true);
btn1.setVisible(false);
}
}
class MyWindowlistenter extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
e.getWindow().setVisible(false);
((Window)e.getComponent()).dispose();
System.exit(0);
}
}