Swing_JProgressBar

来源:互联网 发布:百度关键词seo 编辑:程序博客网 时间:2024/04/27 14:11

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


public class loadPicture extends JFrame {
    JLabel lbl_picture = new JLabel();
    JProgressBar pb_rute = new JProgressBar(1,200);
    Timer timer;
    int n = 200;
    public loadPicture() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        lbl_picture.setIcon(new ImageIcon(loadPicture.class.getResource(
                "pic.jpg")));
        lbl_picture.setBounds(new Rectangle(33, 9, 253, 226));
        pb_rute.setBounds(new Rectangle(7, 253, 309, 35));
        pb_rute.setStringPainted(true);
        pb_rute.setString("正在加载程序....");
        this.getContentPane().add(pb_rute);
        this.getContentPane().add(lbl_picture);
        this.setSize(340,340);
        this.toFront();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation((screenSize.width-395)/2,(screenSize.height-302)/2 );
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
        timer = new Timer(100,new AbstractAction(){   
                public void actionPerformed(ActionEvent e) {
                    if(-- n >= 0)
                    {
                        pb_rute.setValue(200-n);
                        timer.restart();
                    }else
                    {
                        timer.stop();
                        closeFrame();
                    }
        }});
       
         
        timer.start();
    }
    private void closeFrame()
    {
        this.dispose();
    }

    public static void main(String[] args)
    {
        loadPicture lp = new loadPicture();
    }
}
 

原创粉丝点击