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 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
public class JInformation extends JFrame {
public static void main(String[] args) {
JLabel label = new JLabel("Génération en cours ...");
JInformation info = new JInformation(label);
info.setVisible(true);
simulation();
changeText("Traitement1", label);
simulation();
changeText("Traitement2", label);
simulation();
changeText("Traitement3", label);
simulation();
info.dispose();
}
private static void simulation() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public JInformation(JLabel label) {
super("Progression :");
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
JProgressBar progressBar = new JProgressBar();
progressBar.setIndeterminate(true);
progressBar.setStringPainted(true);
panel.add("North", label);
panel.add("South", progressBar);
this.setContentPane(panel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(250, 75);
this.setLocationRelativeTo(null);
}
private static void changeText(final String s, final JLabel label) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
label.setText(s);
}
});
}
} |
Partager