?? test.java
字號:
import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JApplet {
private JProgressBar pb = new JProgressBar();
public void init() {
Container contentPane = getContentPane();
final JButton startButton = new JButton("start");
contentPane.setLayout(new FlowLayout());
contentPane.add(startButton);
contentPane.add(pb);
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GetInfoThread t = new GetInfoThread(Test.this);
t.start();
// this is not okay because invokeAndWait cannot
// be called from the event dispatch thread
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
startButton.setEnabled(false);
}
});
}
catch(Exception ex) {
ex.printStackTrace();
}
}
});
}
public JProgressBar getProgressBar() {
return pb;
}
}
class GetInfoThread extends Thread {
Runnable runnable;
int value;
public GetInfoThread(final Test applet) {
runnable = new Runnable() {
public void run() {
JProgressBar pb = applet.getProgressBar();
pb.setValue(value);
}
};
}
public void run() {
while(true) {
try {
Thread.currentThread().sleep(500);
// This is okay because the runnable's run()
// is invoked on the event dispatch thread
value = (int)(Math.random() * 100);
SwingUtilities.invokeLater(runnable);
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -