?? eventdemo.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+" ");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -