Hello,
I'm trying to build a class that shows a progressbar.
But when I want to try this he only shows me the frame with the progressbar, but it doesn't function like it should be.
This is just a test to see how a progressbar works.
In a later phase I want to implement this class in a program that can call this to show a progressbar. Is it possible to work with 2 frames. In the first frame I like to do some calculatens while these are busy I like to show the second frame with the progressbar. (or do I have to place the progressbar in the same frame)
Thanks in advance
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Progress extends JFrame{
public static JProgressBar progressBar;
public Progress(){
Dimension scrSize= Toolkit.getDefaultToolkit().getScreenSize();
this.setTitle("Vooruitgang.....");
this.setSize(250, 50);
this.setVisible(true);
this.setResizable(false);
this.setLocation((scrSize.width - 500)/2, (scrSize.height - 200)/2);
progressBar = new JProgressBar();
}
public static void main(String[] args) {
new Progress();
initProgressBar(25000);
for (int i=0; i<=25000; i+=1){
iterate(i);
}
}
public static void initProgressBar(int end){
progressBar.setMinimum(0);
progressBar.setMaximum(end);
progressBar.setValue(0);
progressBar.setString("0% completed");
progressBar.setStringPainted(true);
}
public static void iterate(int progress){
progressBar.setValue(progress);
progressBar.setString(progress + "%completed");
}
}
I'm trying to build a class that shows a progressbar.
But when I want to try this he only shows me the frame with the progressbar, but it doesn't function like it should be.
This is just a test to see how a progressbar works.
In a later phase I want to implement this class in a program that can call this to show a progressbar. Is it possible to work with 2 frames. In the first frame I like to do some calculatens while these are busy I like to show the second frame with the progressbar. (or do I have to place the progressbar in the same frame)
Thanks in advance
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Progress extends JFrame{
public static JProgressBar progressBar;
public Progress(){
Dimension scrSize= Toolkit.getDefaultToolkit().getScreenSize();
this.setTitle("Vooruitgang.....");
this.setSize(250, 50);
this.setVisible(true);
this.setResizable(false);
this.setLocation((scrSize.width - 500)/2, (scrSize.height - 200)/2);
progressBar = new JProgressBar();
}
public static void main(String[] args) {
new Progress();
initProgressBar(25000);
for (int i=0; i<=25000; i+=1){
iterate(i);
}
}
public static void initProgressBar(int end){
progressBar.setMinimum(0);
progressBar.setMaximum(end);
progressBar.setValue(0);
progressBar.setString("0% completed");
progressBar.setStringPainted(true);
}
public static void iterate(int progress){
progressBar.setValue(progress);
progressBar.setString(progress + "%completed");
}
}