码迷,mamicode.com
首页 > 编程语言 > 详细

线程的中断

时间:2019-04-03 18:06:25      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:cat   count   read   size   []   opera   star   border   bsp   

public class JoinTest extends JFrame {

    private Thread threadA;
    final JProgressBar progressBar = new JProgressBar();

    public JoinTest() {
        // TODO Auto-generated constructor stub
        getContentPane().add(progressBar, BorderLayout.NORTH);
        progressBar.setStringPainted(true);

        threadA = new Thread(new Runnable() {
            int count = 0;

            public void run() {
                while (true) {
                    progressBar.setValue(++count);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        // TODO: handle exception
                        System.out.println("当前线程序被中断");
                        break;
                    }
                }
            }
        });
        threadA.start();
        threadA.interrupt();
    }
    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);
    }

}

 

线程的中断

标签:cat   count   read   size   []   opera   star   border   bsp   

原文地址:https://www.cnblogs.com/dulute/p/10650428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!