@@ -31,6 +31,7 @@ public class Preferences {
31
31
32
32
private int rotateValue ;
33
33
private boolean end ;
34
+ private Thread thread ;
34
35
35
36
public static void display () {
36
37
JFrame frame = new JFrame ("Preferences" );
@@ -61,36 +62,40 @@ public void actionPerformed(ActionEvent e) {
61
62
R .config .setAnimate (enabledRadioButton .isSelected ());
62
63
R .config .setRenderMode (designMode .getSelectedIndex ());
63
64
R .config .setColor (color .getForeground ());
65
+ kill ();
64
66
frame .dispose ();
65
67
}
66
68
});
67
69
cancelButton .addActionListener (new ActionListener () {
68
70
@ Override
69
71
public void actionPerformed (ActionEvent e ) {
72
+ kill ();
70
73
frame .dispose ();
71
74
}
72
75
});
73
76
frame .addWindowListener (new WindowAdapter () {
74
77
@ Override
75
78
public void windowClosing (WindowEvent e ) {
76
- end = true ;
79
+ kill () ;
77
80
super .windowClosing (e );
78
81
}
79
82
});
80
83
color .addMouseListener (new MouseAdapter () {
81
84
@ Override
82
85
public void mouseClicked (MouseEvent e ) {
83
- super .mouseClicked (e );
84
86
color .setForeground (JColorChooser .showDialog (panel1 , "Choose a color" , color .getForeground ()));
87
+ super .mouseClicked (e );
85
88
}
86
89
});
87
90
88
91
end = false ;
89
- new Thread () {
92
+ thread = new Thread () {
90
93
@ Override
91
94
public void run () {
95
+ int l = 0 ;
92
96
while (true ) {
93
97
for (int i = 45 ; i > 0 ; i --) {
98
+ System .out .println ("alive-" + i +":" +l );
94
99
if (end ) {
95
100
return ;
96
101
}
@@ -102,9 +107,11 @@ public void run() {
102
107
e .printStackTrace ();
103
108
}
104
109
}
110
+ l ++;
105
111
}
106
112
}
107
- }.start ();
113
+ };
114
+ thread .start ();
108
115
109
116
onClickDisableOther (enabledRadioButton , disabledRadioButton );
110
117
onClickDisableOther (disabledRadioButton , enabledRadioButton );
@@ -134,6 +141,11 @@ public void mouseClicked(MouseEvent e) {
134
141
});
135
142
}
136
143
144
+ private void kill () {
145
+ end = true ;
146
+ thread .interrupt ();
147
+ }
148
+
137
149
private void update () {
138
150
Integer mode = R .config .getRenderMode ();
139
151
R .config .setRenderMode (designMode .getSelectedIndex ());
0 commit comments