日期:2014-05-20 浏览次数:20655 次
import java.awt.*; import java.awt.event.*; public class MyButton extends Button { private MyButton MB=null; public MyButton() { enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK); } public void setfriend(MyButton MB) { this.MB=MB; } protected void processMouseMotionEvent(MouseEvent e) { setVisible(false); MB.setVisible(true); } }
import java.awt.*; import java.awt.event.*; public class TestMyButton extends Frame { public static void main(String []args) { TestMyButton tmb=new TestMyButton(); MyButton mb1=new MyButton(); MyButton mb2=new MyButton(); tmb.add(mb1,"North"); tmb.add(mb2,"South"); tmb.setSize(400,400); tmb.setVisible(true); mb1.setfriend(mb2);//谁能给讲解下,此处为什么为死循环; mb2.setfriend(mb1);//谁能给讲解下,此处为什么为死循环; mb2.setVisible(false); } }