[Java] 进度条 →→→→→进入此内容的聊天室

来自 , 2019-05-27, 写在 Java, 查看 102 次.
URL http://www.code666.cn/view/f63f65b5
  1. package wang1;
  2.  
  3.  
  4. import java.awt.EventQueue;
  5. import java.awt.Toolkit;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JScrollBar;
  10. import javax.swing.JTextField;
  11. import javax.swing.SwingUtilities;
  12.  
  13.  
  14. import javax.swing.JProgressBar;
  15. import javax.swing.JLabel;
  16. import java.awt.Color;
  17.  
  18. public class JProcessBar  extends JFrame {
  19.  
  20.     // 得到显示器屏幕的宽高
  21.     public static int width = Toolkit.getDefaultToolkit().getScreenSize().width;
  22.     public static int height = Toolkit.getDefaultToolkit().getScreenSize().height;
  23.     // 定义窗体的宽高
  24.     public static int windowsWedth = 600;
  25.     public static int windowsHeight = 600;
  26.  
  27.     private static final long serialVersionUID = 1L;
  28.  
  29.     private JProgressBar progressBar = new JProgressBar();
  30.  
  31.  
  32.     private boolean state = false;
  33.     private int count = 0;
  34.  
  35.     // 工作线程workThead
  36.     private Thread workThead = null;
  37.     private Runnable run = null;
  38.  
  39.      
  40.     public static void main(String[] args) {
  41.  
  42.         JProcessBar jp = new JProcessBar();
  43.         jp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44.         jp.setVisible(true);
  45.     }
  46.  
  47.     /**
  48.      * Create the application.
  49.      */
  50.     public JProcessBar() {
  51.          
  52.         initialize();
  53.     }
  54. JLabel lblNewLabel_1 = new JLabel("");
  55.     /**
  56.      * Initialize the contents of the frame.
  57.      */
  58.     private void initialize() {
  59.         this.setTitle("\u52A0\u8F7D\u4E2D");
  60.         this.setBounds((width - windowsWedth) / 2, (height - windowsHeight) / 2, 545, 186);
  61.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  62.         this.getContentPane().setLayout(null);
  63.         progressBar.setForeground(Color.BLACK);
  64.         progressBar.setStringPainted(true);
  65.         progressBar.setOpaque(false);
  66.         progressBar.setBounds(73, 103, 434, 24);
  67.         this.getContentPane().add(progressBar);
  68.          
  69.         JLabel lblNewLabel = new JLabel("\u8FDB\u5EA6\u52A0\u8F7D\uFF1A");
  70.         lblNewLabel.setBounds(10, 106, 68, 15);
  71.         this.getContentPane().add(lblNewLabel);
  72.         lblNewLabel_1.setOpaque(true);
  73.         lblNewLabel_1.setBounds(73, 80, 235, 24);
  74.         getContentPane().add(lblNewLabel_1);
  75.          
  76.         if (workThead == null) {
  77.             state = true;
  78.             workThead = new WorkThead();
  79.             workThead.start();
  80.         }
  81.     }
  82.     class WorkThead extends Thread {
  83.  
  84.         public void run() {
  85.  
  86.             while (count < 100) {
  87.  
  88.                 try {
  89.                     Thread.sleep(100);
  90.                 } catch (InterruptedException e) {
  91.                     // TODO Auto-generated catch block
  92.                     e.printStackTrace();
  93.                 }
  94.  
  95.                 if (state) {
  96.                     count++;
  97.                     SwingUtilities.invokeLater(new Runnable() {
  98.  
  99.                         @Override
  100.                         public void run() {
  101.                             // TODO Auto-generated method stub
  102.                             // 更新操作通过事件派发线程完成(一般实现Runnable()接口)
  103.                             progressBar.setValue(count);
  104.                             if(count==5){
  105.                             lblNewLabel_1.setText("loading api-ms-win-core-xstate-l1-1-0.dll");
  106.                             }else if(count==10){
  107.                                 lblNewLabel_1.setText("loading MaxxAudioAPO5064.dll");
  108.                             }else if(count==20){
  109.                                 lblNewLabel_1.setText("loading MetroIntelGenericUIFramework.dll");
  110.                             }else if(count==30){
  111.                                 lblNewLabel_1.setText("loading microsoft-windows-kernel-power-events.dll");
  112.                             }else if(count==40){
  113.                                 lblNewLabel_1.setText("miguiresource.dll");
  114.                             }else if(count==80){
  115.                                 lblNewLabel_1.setText("loading mfvdsp.dll");
  116.                             }else if(count==90){
  117.                                 lblNewLabel_1.setText("loading miguiresource.dll");
  118.                             }else if(count==100){
  119.                                 lblNewLabel_1.setText("loading end");
  120.                                 Thread.currentThread();
  121.                                                                 try {
  122.                                                                         Thread.sleep(500);
  123.                                                                 } catch (InterruptedException e) {
  124.                                                                         // TODO 自动生成的 catch 块
  125.                                                                         e.printStackTrace();
  126.                                                                 }
  127.                              
  128.                             }
  129.                         }
  130.                     });
  131.                 }
  132.             }
  133.         }
  134.  
  135.     }
  136. }
  137.  

回复 "进度条"

这儿你可以回复上面这条便签

captcha