2022-06-19 21:01:30 +02:00
|
|
|
package fenetres;
|
2022-06-04 15:43:08 +02:00
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.Container;
|
|
|
|
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JProgressBar;
|
|
|
|
import javax.swing.SwingUtilities;
|
|
|
|
|
|
|
|
public class ProgressBar extends JFrame implements Runnable{
|
|
|
|
|
2022-06-06 09:50:45 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
@Override
|
2022-06-04 15:43:08 +02:00
|
|
|
public void run() {
|
|
|
|
ProgressBar myProgressBar = new ProgressBar();
|
|
|
|
int i = 0;
|
|
|
|
while (i <= 100) {
|
|
|
|
System.out.println("" + i + "%");
|
|
|
|
myProgressBar.setValue(i);
|
|
|
|
try {
|
|
|
|
Thread.sleep(50);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i = i + 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private JProgressBar bar;
|
|
|
|
|
|
|
|
public ProgressBar() {
|
|
|
|
super("loading");
|
|
|
|
setSize(200, 100);
|
|
|
|
Container content = getContentPane();
|
|
|
|
content.setLayout(new BorderLayout());
|
|
|
|
bar = new JProgressBar();
|
|
|
|
bar.setMinimum(0);
|
|
|
|
bar.setMaximum(100);
|
|
|
|
bar.setStringPainted(true);
|
|
|
|
bar.setBorder(null);
|
|
|
|
content.add(bar, BorderLayout.SOUTH);
|
|
|
|
setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateProgress(final int newValue) {
|
|
|
|
bar.setValue(newValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setValue(final int j) {
|
|
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
updateProgress(j);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(final String Args[]) {
|
|
|
|
ProgressBar myProgressBar = new ProgressBar();
|
|
|
|
int i = 0;
|
|
|
|
while (i <= 100) {
|
|
|
|
System.out.println("" + i + "%");
|
|
|
|
myProgressBar.setValue(i);
|
|
|
|
try {
|
|
|
|
Thread.sleep(50);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i = i + 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|