zoukankan      html  css  js  c++  java
  • 线程的加入

    public class JoinTest extends JFrame {
    
        private Thread threadA;
        private Thread threadB;
        final JProgressBar progressBar = new JProgressBar();
        final JProgressBar progressBar2 = new JProgressBar();
        int count = 0;
    
        public JoinTest() {
            // TODO Auto-generated constructor stub
            getContentPane().add(progressBar, BorderLayout.NORTH);
            getContentPane().add(progressBar2, BorderLayout.SOUTH);
            progressBar.setStringPainted(true);
            progressBar2.setStringPainted(true);
    
            threadA = new Thread(new Runnable() {
                int count = 0;
    
                public void run() {
                    while (true) {
                        progressBar.setValue(++count);
                        try {
                            Thread.sleep(100);
                            threadB.join();
                        } catch (Exception e) {
                            // TODO: handle exception
                            e.printStackTrace();
                        }
                    }
                }
            });
            threadA.start();
            threadB = new Thread(new Runnable() {
                int count = 0;
                public void run() {
                    while (true) {
                        progressBar2.setValue(++count);
                        try {
                            Thread.sleep(100);
                        } catch (Exception e) {
                            // TODO: handle exception
                            e.printStackTrace();
                        }
                        if(count==100)
                            break;
                    }
                }
            });
            threadB.start();
        }
        public static void init(JFrame frame,int width,int height) {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(width, height);
            frame.setVisible(true);
        }
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            init(new JoinTest(), 100, 100);
        }
    
    }
  • 相关阅读:
    Linux终端复用——tmux
    python中的global和nonlocal
    Pytorch中的错误和bug
    vue之Mutations 理解
    js 对象的合并(3种方法)转载
    json 数组
    vue-cli 安装时 npm 报错 errno -4048
    vue-cli 安装步骤(转载)
    安卓输入框调起键盘后输入框自动上浮
    jquery on 事件嵌套 事件执行多次
  • 原文地址:https://www.cnblogs.com/dulute/p/10650361.html
Copyright © 2011-2022 走看看