CSDN博客

img wuhongze

自己做的觉得好玩的第一个JAVA程序

发表于2004/10/14 17:36:00  796人阅读

分类: JAVA专栏

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);
 }
}
阅读全文
0 0

相关文章推荐

img
取 消
img