Hola, estoy en el trabajo y no puedo probar el código pero prueba así a ver si te funciona.
Si algo, comenta.
Saludos.
Código (java) [Seleccionar]
package base;
import java.util.Calendar;
import javax.swing.SwingWorker;
public class CheckTime extends SwingWorker{
private int copyHour;
private int copyMin;
private int copySec;
private boolean running;
public CheckTime(int hour,int min, int sec){
copyHour = hour;
copyMin = min;
copySec = sec;
}
protected Object doInBackground() throws Exception {
Calendar calendario;
int thisHour;
int thisMin;
int thisSec;
System.out.println("iniciado!");
this.running = true;
do{
calendario = Calendar.getInstance();
thisHour = calendario.get(Calendar.HOUR_OF_DAY);
thisMin = calendario.get(Calendar.MINUTE);
thisSec = calendario.get(Calendar.SECOND);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("Thread sleep de ChekcHour a fallado");
}
}while(copyHour != thisHour || copyMin != thisMin || copySec != thisSec || this.running);
System.out.println("APAGATE!");
return null;
}
public void stopThread() {
running = false;
}
Código (java) [Seleccionar]
public void actionPerformed(ActionEvent evt) {
CheckTime time = new CheckTime(hour.getSelectedIndex(), min.getSelectedIndex(), sec.getSelectedIndex());
if(evt.getSource() == programShutdown && isStarted == false){
System.out.println("iniciado!");
time.execute();
isStarted = true;
} else if(evt.getSource() == cancelShutdown && isStarted == true){
System.out.println("cancelado!");
time.stopThread();
isStarted = false;
}
}
Si algo, comenta.
Saludos.