java中打开的线程怎么关闭_[求助] 用线程怎么关闭运行中的窗口
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
package testOfProject;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ThreadView extends JFrame implements ActionListener {
JPanel jp1;
JButton jb1, jb2;
public static void main(String[] args) {
ThreadView mysf = new ThreadView();
}
// 構造函數
public ThreadView() {
jp1 = new JPanel();
jb1 = new JButton("啟動服務器");
jb1.addActionListener(this);
jb2 = new JButton("關閉服務器");
jb2.addActionListener(this);
jp1.add(jb1);
jp1.add(jb2);
this.add(jp1);
this.setSize(500, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
if (arg0.getSource() == jb1) {
new MyFunction();
}else if (arg0.getSource() == jb2) {
System.exit(0);
}
}
}
package testOfProject;
public class MyFunction {
public MyFunction() {
int a = 1;
System.out.println("Sever is running");
while (true) {
a++;
a--;
}
}
}
總結
以上是生活随笔為你收集整理的java中打开的线程怎么关闭_[求助] 用线程怎么关闭运行中的窗口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA程序禁用Hbase中的表_HBa
- 下一篇: java如何將數組反轉_Java基礎練習