自己的第一个JAVA程序

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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);

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航