I have build a GUI for the popurse that when I click the checkbox button,the corresponding thread will suspend or wake up.But it doesn't come out with the expected result.
class itemStateChangedHandler implements ItemListener {
public void itemStateChanged(ItemEvent e) {
JCheckBox jcheckbox = (JCheckBox) e.getItem();
String s = jcheckbox.getText();
if (jcheckbox.isSelected() == true) {
try {
switch (s) {
case "Thread 1 suspend":
synchronized(t1) {
t1.wait();
}
break;
case "Thread 2 suspend":
synchronized(t2) {
t2.wait();
}
break;
case "Thread 3 suspend":
synchronized(t3) {
t3.wait();
}
break;
}
} catch (InterruptedException ex) {}
} else {
switch (s) {
case "Thread 1 wake up":
synchronized(t1) {
t1.notify();
}
break;
case "Thread 2 wake up":
synchronized(t2) {
t1.notify();
}
break;
case "Thread 3 wake up":
synchronized(t3) {
t1.notify();
}
break;
}
}
}
}`