JAVA线程的加入

package lll;
import java.awt.*;
import javax.swing.*;
public class ccc extends JFrame{
    private Thread threadA;
    private Thread threadB;
    final JProgressBar pb1 =new JProgressBar();
    final JProgressBar pb2 =new JProgressBar();
    int count =0;
    public ccc(){
        super();
        getContentPane().add(pb1,BorderLayout.NORTH);
        getContentPane().add(pb2,BorderLayout.SOUTH);
        pb1.setStringPainted(true);
        pb2.setStringPainted(true);

    threadA =new Thread(new Runnable(){
        int count=0;
        public void run(){
            while(true){
                pb1.setValue(++count);
                try{
                    threadA.sleep(100);
                    threadB.join();
                }catch(Exception e){
                    e.printStackTrace();
                }
                if(count==100)
                    break;
            }
        }
    });
    threadA.start();
    threadB =new Thread(new Runnable(){
        int count =0;
        public void run() {
            while(true){
                pb2.setValue(++count);
                try{
                    Thread.sleep(100);
                }catch(Exception e){
                    e.printStackTrace();
                }
                if(count==100)
                    break;
            }
        }
        
    });
    threadB.start();
    }
    public static void main(String[] args){
        init(new ccc(),100,100);
    }
    private static void init(ccc ccc, int i, int j) {
        ccc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ccc.setSize(i,j);
        ccc.setVisible(true);
    }
}

    

 

posted @ 2019-10-16 15:18  源霸霸丿  阅读(159)  评论(0编辑  收藏  举报