1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class XrdIProgression
{
JProgressBar progress;
Thread monThread;
int rappidite;
JFrame cadre;
public void go(int rappid)
{
rappidite=rappid;
// Interface
cadre = new JFrame("Loading");
JPanel panneau = new JPanel();
JLabel texte = new JLabel("Please wait...");
progress = new JProgressBar(0, 100);
panneau.add("Center", progress);
panneau.add("Center", texte);
cadre.getContentPane().add(BorderLayout.CENTER, panneau);
cadre.setSize(300,100);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); // screen resolution
cadre.setLocation( (screen.width - cadre.getSize().width)/2, (screen.height - cadre.getSize().height)/2 );
cadre.setVisible(true);
cadre.setResizable(false);
cadre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// thread creation
monThread= new Thread(new MonRunnable());
monThread.start();
}
public class MonRunnable implements Runnable
{
public void run()
{
for (int j = 1; j < 100; j++) // running of the progress bar
{
progress.setValue(j);
try
{
monThread.sleep(rappidite);
}
catch(Exception e)
{
e.printStackTrace();
}
}
cadre.dispose(); // end of loading
}
}
} |
Partager