@@ -31,6 +31,7 @@ public class Preferences {
3131
3232 private int rotateValue ;
3333 private boolean end ;
34+ private Thread thread ;
3435
3536 public static void display () {
3637 JFrame frame = new JFrame ("Preferences" );
@@ -61,36 +62,40 @@ public void actionPerformed(ActionEvent e) {
6162 R .config .setAnimate (enabledRadioButton .isSelected ());
6263 R .config .setRenderMode (designMode .getSelectedIndex ());
6364 R .config .setColor (color .getForeground ());
65+ kill ();
6466 frame .dispose ();
6567 }
6668 });
6769 cancelButton .addActionListener (new ActionListener () {
6870 @ Override
6971 public void actionPerformed (ActionEvent e ) {
72+ kill ();
7073 frame .dispose ();
7174 }
7275 });
7376 frame .addWindowListener (new WindowAdapter () {
7477 @ Override
7578 public void windowClosing (WindowEvent e ) {
76- end = true ;
79+ kill () ;
7780 super .windowClosing (e );
7881 }
7982 });
8083 color .addMouseListener (new MouseAdapter () {
8184 @ Override
8285 public void mouseClicked (MouseEvent e ) {
83- super .mouseClicked (e );
8486 color .setForeground (JColorChooser .showDialog (panel1 , "Choose a color" , color .getForeground ()));
87+ super .mouseClicked (e );
8588 }
8689 });
8790
8891 end = false ;
89- new Thread () {
92+ thread = new Thread () {
9093 @ Override
9194 public void run () {
95+ int l = 0 ;
9296 while (true ) {
9397 for (int i = 45 ; i > 0 ; i --) {
98+ System .out .println ("alive-" + i +":" +l );
9499 if (end ) {
95100 return ;
96101 }
@@ -102,9 +107,11 @@ public void run() {
102107 e .printStackTrace ();
103108 }
104109 }
110+ l ++;
105111 }
106112 }
107- }.start ();
113+ };
114+ thread .start ();
108115
109116 onClickDisableOther (enabledRadioButton , disabledRadioButton );
110117 onClickDisableOther (disabledRadioButton , enabledRadioButton );
@@ -134,6 +141,11 @@ public void mouseClicked(MouseEvent e) {
134141 });
135142 }
136143
144+ private void kill () {
145+ end = true ;
146+ thread .interrupt ();
147+ }
148+
137149 private void update () {
138150 Integer mode = R .config .getRenderMode ();
139151 R .config .setRenderMode (designMode .getSelectedIndex ());
0 commit comments