destroyProcesses(processes);
因此,当我单击 my stopButton
which is a时,我想做JButton
。我如何让它在我的代码中工作?
这是我的代码:
private void Processes() throws IOException, InterruptedException {
// New Thread "processesThread" will start here.
final Object mon = threadBlock;
Thread processesThread = new Thread(new Runnable() {
@Override
public void run() {
synchronized (mon) {
try {
try {
Runtime rt = Runtime.getRuntime();
List<Process> processes = new ArrayList<Process>();
// "runnableTogether" will be the number that the user inputs in the GUI.
switch (runnableTogether) {
case 4:
processes.add(rt.exec("C:/Windows/System32/SoundRecorder.exe"));
case 3:
processes.add(rt.exec("C:/Windows/System32/taskmgr.exe"));
case 2:
processes.add(rt.exec("C:/Windows/System32/notepad.exe"));
case 1:
processes.add(rt.exec("C:/Windows/System32/calc.exe"));
Thread.sleep(5000);
destroyProcesses(processes);
break;
default:
System.exit(0);
break;
}
mon.wait();
} catch (IOException ex) {
}
} catch (InterruptedException ex) {
}
}
}
});
processesThread.start();
// New Thread "processesThread" will end here.
}
private void destroyProcesses(List<Process> processes) {
if (processes == null) {
return;
}
else {
for (Process thisProcess : processes) {
thisProcess.destroy();
}
processes.clear();
}
}
public void actionPerformed(final ActionEvent e) {
if (e.getSource() == stopButton) {
try {
// Destroy processes here.
System.exit(0);
}
catch (Exception ex) {
}
}
}
有任何想法吗?