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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| package toto;
import static com.sun.org.apache.regexp.internal.RETest.test;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javafx.concurrent.Task;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import static jdk.nashorn.internal.objects.NativeRegExp.test;
public class Progress extends JFrame{
public String fin_process;
public Thread t;
private JProgressBar bar;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private String nom;
public Progress(){
this.nom ="toto";
this.setSize(300, 50);
this.setTitle("frame");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
t = new Thread(new Traitement());
bar = new JProgressBar();
bar.setMaximum(5);
bar.setMinimum(0);
bar.setStringPainted(true);
//bar.setSize(100,10);
jLabel2 = new javax.swing.JLabel("Action en cours : ");
jLabel3 = new javax.swing.JLabel("");
jLabel4 = new javax.swing.JLabel("");
jLabel5 = new javax.swing.JLabel("");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel3)
.addGroup(layout.createSequentialGroup()
.addGap(103, 103, 103)
.addComponent(bar, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel5)
.addComponent(jLabel2))
.addContainerGap(138, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addContainerGap(64, Short.MAX_VALUE))
);
t.start();
System.out.println(", status = " + t.isAlive());
//t.join();
this.setVisible(true);
pack();
}
class Traitement implements Runnable{
public void run(){
for(int val = 0; val <= 5; val++){
try {
bar.setValue(val);
switch (val) {
case 0: new Action1();
jLabel2.setText("Action en cours : vérification de l'incrémentation des fichiers");
jLabel3.setText("Fichier de ranging bien sauvegardé !");
pack();
break;
case 1: new Action2();jLabel2.setText("Action2");
jLabel2.setText("Action en cours : action2");
jLabel4.setText("Action1 achevé !");
break;
case 2: new Action4();jLabel2.setText("Action3");
jLabel2.setText("Action en cours : action3");
jLabel4.setText("ACtion2 achevé !");break;
case 3: new Action3();jLabel2.setText("Action4");jLabel2.setText("Action en cours : action3");
jLabel5.setText("ACtion3 achevé !");break;
case 4: new Action5();jLabel2.setText("Action5");break;
case 5: new Action6();jLabel2.setText("Action6");break;
}
try {
t.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (InterruptedException ex) {
Logger.getLogger(Progress.class.getName()).log(Level.SEVERE, null, ex);
}
}
setVisible(false);
System.out.println("fin");
System.out.println(", status fin = " + t.isAlive());
setVisible(false);
}
}
} |
Partager