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); } }
JAVA线程的加入
猜你喜欢
转载自www.cnblogs.com/YShen0/p/11685697.html
今日推荐
周排行