Tuesday, July 26, 2011

progress Bar in swing

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class SplashScreen extends JWindow
{
private static JProgressBar progressBar = new JProgressBar();
private static SplashScreen execute;
private static int count;
private static Timer timer1;
public SplashScreen()
{

setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new javax.swing.border.EtchedBorder());
panel.setBackground(Color.red);
panel.setBounds(10,10,348,150);
panel.setLayout(null);

add(panel);
JLabel label = new JLabel("Hello World!");
label.setFont(new Font("Verdana",Font.BOLD,14));
label.setBounds(85,25,280,30);
panel.add(label);

progressBar.setMaximum(50);
progressBar.setBounds(55, 180, 250, 15);

add(progressBar);
loadProgressBar();
setSize(375,300);
setLocationRelativeTo(null);
setVisible(true);
}
public void loadProgressBar()
{
ActionListener al = new ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
count++;
progressBar.setValue(count);
if (count == 51){
timer1.stop();
execute.setVisible(false);

//load the rest of your application

}
}};
timer1 = new Timer(300, al);
timer1.start();
}

public static void main (String args[]){
execute = new SplashScreen();
}
}

0 comments:

Post a Comment