亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問我的這個線程要怎么停掉?

請問我的這個線程要怎么停掉?

慕田峪9158850 2019-03-21 22:19:39
因為是另外一個窗口調用了次類,所以使用JFrame.DISPOSE_ON_CLOSE以免把其他窗口都關了。但是退出的時候并沒有把另外一個線程關掉。public class ABC extends JFrame implements Runnable {    public static void main(String[] args) {        ABC abc= new ABC();    }        public ABC(){        Thread thread = new Thread(this);    //此處的線程還在運行        thread.start();                this.setSize(600,430);        this.setResizable(false);//固定窗體大小        this.setLocationRelativeTo(null);//打開時相對window居中        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);    //此處會導致退出窗口后線程還在運行        this.setVisible(true);    }        @Override    public void run() {        while (true){            System.out.println("ABC");            try {                Thread.sleep(1000);            }catch (Exception e){                e.printStackTrace();            }        }    }}
查看完整描述

1 回答

?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

做個開關。
比如在while上做個變量判斷,窗口退出時修改該變量,使while結束。

查看完整回答
反對 回復 2019-04-17
  • 1 回答
  • 0 關注
  • 394 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號