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

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

回复 "进度条"

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

captcha