R
Russell
I'm playing with the idea of showing a JProgressBar in a small App' I trying
to make.
I want to display the progress of an array being populated....however I cant
seem to get the bar to show the actual % state before it reaches 100%
Am I missing something out?
Please help me if you can..
Thanks...
#######################
CODE BELOW
#######################
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ArrayRandom extends JFrame {
protected final int size = 100000;
protected int[] prodRandm = new int[size];
protected int min = 0;
protected int max = 100;
protected JProgressBar progress;
protected JButton start;
public ArrayRandom() {
setSize(300,50);
progress = new JProgressBar();
progress.setStringPainted(false);
progress.setIndeterminate(true);
start = new JButton("Start");
ActionListener act = new ActionListener() {
public void actionPerformed(ActionEvent e) {
progress.setMinimum(min);
progress.setMaximum(max);
progress.setIndeterminate(false);
progress.setStringPainted(true);
for (int i = 0; i < size; i++) {
prodRandm = i;
progress.setValue((i/1000)+1);
progress.setString((i/1000)+1+" %");
}
}
};
start.addActionListener(act);
getContentPane().setLayout(new BorderLayout(10,10));
getContentPane().add(progress, BorderLayout.CENTER);
getContentPane().add(start, BorderLayout.WEST);
}
public static void main(String[] args) {
ArrayRandom frame = new ArrayRandom();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
to make.
I want to display the progress of an array being populated....however I cant
seem to get the bar to show the actual % state before it reaches 100%
Am I missing something out?
Please help me if you can..
Thanks...
#######################
CODE BELOW
#######################
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ArrayRandom extends JFrame {
protected final int size = 100000;
protected int[] prodRandm = new int[size];
protected int min = 0;
protected int max = 100;
protected JProgressBar progress;
protected JButton start;
public ArrayRandom() {
setSize(300,50);
progress = new JProgressBar();
progress.setStringPainted(false);
progress.setIndeterminate(true);
start = new JButton("Start");
ActionListener act = new ActionListener() {
public void actionPerformed(ActionEvent e) {
progress.setMinimum(min);
progress.setMaximum(max);
progress.setIndeterminate(false);
progress.setStringPainted(true);
for (int i = 0; i < size; i++) {
prodRandm = i;
progress.setValue((i/1000)+1);
progress.setString((i/1000)+1+" %");
}
}
};
start.addActionListener(act);
getContentPane().setLayout(new BorderLayout(10,10));
getContentPane().add(progress, BorderLayout.CENTER);
getContentPane().add(start, BorderLayout.WEST);
}
public static void main(String[] args) {
ArrayRandom frame = new ArrayRandom();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}