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 33 34 35 36 37 38 39 40 41 42 43
| package test;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class WaitTest implements ActionListener {
JFrame _waitDialog;
public static void main(String[] args) {
WaitTest wt = new WaitTest();
wt.showWaitWindow();
wt.doComplexJob();
}
private void doComplexJob() {
try {
// Le job en question peut être remplacé par ton appel à une tentative de connexion à ta base
System.out.println("our job is just to sleep, not very hard indeed...");
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("hey, wake up and notify");
this.actionPerformed(null);
}
private void showWaitWindow() {
_waitDialog = new JFrame();
_waitDialog.getContentPane().add(new JLabel("waiting ..."));
_waitDialog.pack();
_waitDialog.setVisible(true);
}
// Juste une callback pour être notifié de la fin d'un traitement.
public void actionPerformed(ActionEvent e) {
_waitDialog.setVisible(false);
_waitDialog.dispose();
_waitDialog = null;
}
} |
Partager