• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

java实现进度条效果3

java实例 海叔叔 4年前 (2021-09-30) 43次浏览 已收录 0个评论

本文由搞代码网为大家展示了java实现进度条效果3》的代码案例,请各位coder不吝赐教,也欢迎coder点赞收藏转发,感谢

package wang1;
 
 
import java.awt.EventQueue;
import java.awt.Toolkit;
  
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
  
  
import javax.swing.JProgressBar;
import javax.swing.JLabel;
import java.awt.Color;
  
public class JProcessBar  extends JFrame {
  
    // 得到显示器屏幕的宽高
    public static int width = Toolkit.getDefaultToolkit().getScreenSize().width;
    public static int height = Toolkit.getDefaultToolkit().getScreenSize().height;
    // 定义窗体的宽高
    public static int windowsWedth = 600;
    public static int windowsHeight = 600;
  
    private static final long serialVersionUID = 1L;
  
    private JProgressBar progressBar = new JProgressBar();
  
  
    private boolean state = false;
    private int count = 0;
  
    // 工作线程workThead
    private Thread workThead = null;
    private Runnable run = null;
  
      
    public static void main(String[] args) {
  
        JProcessBar jp = new JProcessBar();
        jp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jp.setVisible(true);
    }
  
    /**
     * Create the application.
     */
    public JProcessBar() {
          
        initialize();
    }
JLabel lblNewLabel_1 = new JLabel("");
    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        this.setTitle("\u52A0\u8F7D\u4E2D");
        this.setBounds((width - windowsWedth) / 2, (height - windowsHeight) / 2, 545, 186);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.getContentPane().setLayout(null);
        progressBar.setForeground(Color.BLACK);
        progressBar.setStringPainted(true);
        progressBar.setOpaque(false);
        progressBar.setBounds(73, 103, 434, 24);
        this.getContentPane().add(progressBar);
          
        JLabel lblNewLabel = new JLabel("\u8FDB\u5EA6\u52A0\u8F7D\uFF1A");
        lblNewLabel.setBounds(10, 106, 68, 15);
        this.getContentPane().add(lblNewLabel);
        lblNewLabel_1.setOpaque(true);
        lblNewLabel_1.setBounds(73, 80, 235, 24);
        getContentPane().add(lblNewLabel_1);
          
        if (workThead == null) {
            state = true;
            workThead = new WorkThead();
            workThead.start();
        }
    }
    class WorkThead extends Thread {
  
        public void run() {
  
            while (count < 100) {
  
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
  
                if (state) {
                    count++;
                    SwingUtilities.invokeLater(new Runnable() {
  
                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            // 更新操作通过事件派发线程完成(一般实现Runnable()接口)
                            progressBar.setValue(count);
                            if(count==5){
                            lblNewLabel_1.setText("loading api-ms-win-core-xstate-l1-1-0.dll");
                            }else if(count==10){
                                lblNewLabel_1.setText("loading MaxxAudioAPO5064.dll");
                            }else if(count==20){
                                lblNewLabel_1.setText("loading MetroIntelGenericUIFramework.dll");
                            }else if(count==30){
                                lblNewLabel_1.setText("loading microsoft-windows-kernel-power-events.dll");
                            }else if(count==40){
                                lblNewLabel_1.setText("miguiresource.dll");
                            }else if(count==80){
                                lblNewLabel_1.setText("loading mfvdsp.dll");
                            }else if(count==90){
                                lblNewLabel_1.setText("loading miguiresource.dll");
                            }else if(count==100){
                                lblNewLabel_1.setText("loading end");
                                Thread.currentThread();
                                try {
                                    Thread.sleep(500);
                                } catch (InterruptedException e) {
                                    // TODO 自动生成的 catch 块
                                    e.printStackTrace();
                                }
                              
                            }
                        }
                    });
                }
            }
        }
  
    }
}

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:java实现进度条效果3
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址