For some reason, when I run the code in the main it works but currently I have the code only run when a JButton is
import java.awt.Color;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
public class JavaCompilingJOP {
private JFrame framed = new JFrame();
private JProgressBar bar = new JProgressBar(0,100); //0 through 100 is the compiling until reaches that number
private Color startProgress = Color.RED;
private int loadingPercent = 0;
public JavaCompilingJOP(){
framed.setLayout(null);
framed.setSize(500, 200);
framed.setTitle("Compiling JOptionPane...");
framed.setLocationRelativeTo(null);
//Ok now lets make the GUI happen boys!
framed.getContentPane().setBackground(Color.BLACK); //Because startProgress is ze theme of ze game!
bar.setForeground(startProgress);
bar.setStringPainted(true);
bar.setValue(loadingPercent);
bar.setString(loadingPercent + "%");
bar.setBounds(50, 50, 400, 100);
framed.add(bar);
System.out.println("Make visible an run!");
framed.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
framed.setResizable(false);
framed.setVisible(true);
doTimer();
}
private void doTimer(){
Random obj = new Random();
for(int i = 0; i < 100; i++){
loadingPercent++;
bar.setValue(loadingPercent); //Updates counter
bar.setString(loadingPercent + "%"); //Updates progressbar
startProgress = new Color(startProgress.getRed()-2,startProgress.getGreen()+2,startProgress.getBlue());
bar.setForeground(startProgress);
try{Thread.sleep(100 + obj.nextInt(200));}catch(Exception E){}
}
System.out.println("Java compiled!");
framed.setVisible(false);
}
}
For some reason all I am getting though when called is a white screen that seems to neglect disposing on close because when I hit to close it.. it doesn't either. Keep in mind that when I run it in the main it works but when inside the ActionListener of the button, it gives me a blank screen that still performs it's progressbar stuff. Im stuck on this.