1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| Public class TestSwing {
@Background
public static void buttonClick(JLabel label) {
Swing.executeInEDT(label.setText, "please wait...");
String result = doLongComputation();
Swing.executeInEDT(label.setText, "result is : "+result);
}
private static String doLongComputation() {
try { Thread.sleep(1000); } catch (InterruptedException e) {}
return "ok";
}
public static void createAndShowGUI() {
JFrame frame = new JFrame("---test---");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new JPanel());
JLabel label = new JLabel();
JButton button = new JButton("START");
button.addActionListener( buttonClick, label );
frame.add(button);
frame.add(label);
frame.setSize(200, 100);
}
public static void main(String[] args) {
Swing.executeInEDT(createAndShowGUI);
}
} |