⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eventdemo.java

📁 演示win32的socket 通讯 八皇后的改进算法 并发Concurrency的JAVA实现 applet演示鼠标的点击时间和显示图象 手机J2ME的多线程演示
💻 JAVA
字号:
/*
@author  j.n.magee 25/04/98
*/
package concurrency.announce;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class EventDemo extends Applet implements ActionListener {
    final static int MAX = 8;
    final static int FAST = 600;
    final static int SLOW = 1200;
    BoxCanvas display;
    Thread movers[] = new Thread[MAX];
    Button goFast,goSlow,end;
    Label gameClicks;
    int clicks = 0;

    Font ff = new Font("Serif",Font.BOLD,14);

    public void init() {
        setLayout(new BorderLayout());
        add("Center",display=new BoxCanvas());
        display.setSize(300,240);
        display.addMouseListener(new MyListener());
        Panel p = new Panel();
        p.add(goFast= new Button("Go Fast"));
        p.add(goSlow= new Button("Go Slow"));
        p.add(gameClicks = new Label("  0  "));
        p.add(end = new Button("End"));
        goFast.addActionListener(this);
        goSlow.addActionListener(this);
        end.addActionListener(this);
        goFast.setFont(ff);
        goSlow.setFont(ff);
        end.setFont(ff);
        gameClicks.setFont(ff);
        gameClicks.setBackground(Color.lightGray);
        setBackground(Color.magenta);
        add("South",p);
    }

    public void go(int speed) {
      display.reset();
      clicks=0;
      gameClicks.setText("  "+clicks+"  ");
      for (int i=0; i<MAX; ++i) {
            movers[i] = new BoxMover(display,i,speed);
            movers[i].start();
        }
    }

    public void stop() {
     for (int i=0; i<MAX; ++i) {
        if (movers[i]!=null && movers[i].isAlive()) {
            movers[i].interrupt();
        }
     }
     //not strictly necessary, however Netscape 4.06 needs it
     try {Thread.sleep(500);} catch(InterruptedException e){}
     for (int i=0; i<MAX; ++i) {
        if (movers[i]!=null) {
             movers[i].stop();
        }
     }
    }

    public void actionPerformed(ActionEvent e) {
        stop();
        if (e.getSource()==goFast)
             go(FAST);
        else if (e.getSource()==goSlow)
             go(SLOW);
     }

    class MyListener extends MouseAdapter {
        public void mousePressed(MouseEvent e) {
            ++clicks;
            gameClicks.setText("  "+clicks+"  ");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -