Как можно завершить поток thread при нажатии на кнопку btn? .interrupt не срабатывает.
Код:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Some {
static MyThread thread = new MyThread();
public static void main(String[] args) {
thread.sw.btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
thread.interrupt();
}
});
thread.run();
}
}
class SimpleWindow extends JFrame {
static JButton btn = new JButton("some_text");
static JTextArea jta = new JTextArea();
static int count = 0;
static Box box = Box.createVerticalBox();
public SimpleWindow() {
super("some_header " + count);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(500, 400);
Box box = Box.createVerticalBox();
box.add(btn);
setContentPane(box);
count++;
}
}
class MyThread extends Thread {
SimpleWindow sw = new SimpleWindow();
@Override
public void run() {
sw.setVisible(true);
}
}