import [Link].
FlowLayout;
import [Link];
import [Link].*;
public class ProgressBarExample {
private static volatile boolean running = true; // Flag to control progress
public static void main(String[] args) {
final int MAXIMUM = 100;
final JFrame jFrame = new JFrame("JProgress Demo ");
// Create Frame
[Link](new FlowLayout());
[Link](JFrame.EXIT_ON_CLOSE);
[Link](300, 200);
// ProgressBar
JProgressBar progressBar = new JProgressBar(0, MAXIMUM);
[Link](true);
[Link](progressBar);
// Stop Button
JButton button = new JButton("Stop");
[Link](button);
[Link](true);
// Background Thread to Update ProgressBar
Thread progressThread = new Thread(() -> {
for (int i = 0; i <= MAXIMUM && running; i++) {
try {
[Link](100); // Simulate work
final int progress = i;
[Link](() -> [Link](progress));
} catch (InterruptedException e) {
[Link](jFrame, "Process Interrupted: " + [Link]());
break;
}
}
});
[Link]();
// Stop Button Action (Stops the Loop)
[Link]((ActionEvent e) -> {
running = false; // Stop the loop
});
}
}