I've got a question about the java.util.timer.
I have a little application, which does use the timer to trigger an alarm.
The timer is set from the Buttonlistener:
if (timer1) {
t1 = new Timer();
t1.schedule(new AlarmTask(),(n_timer1.getInt()*60000),(n_timer1.getInt()*60000)+(n_delay1.getInt()*1000));
ti1 = n_timer1.getInt()*60;
bt_timer1.setText("Stop");
timer1 = false;
}
else {
t1.cancel();
timer1 = true;
bt_timer1.setText("Start");
}
and it's triggering the AlarmTask():
class AlarmTask extends TimerTask
{
@Override public void run()
{
try {
File yourFile = new File("alarm.wav");
AudioInputStream stream;
AudioFormat format;
DataLine.Info info;
Clip clip;
stream = AudioSystem.getAudioInputStream(yourFile);
format = stream.getFormat();
info = new DataLine.Info(Clip.class, format);
clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
clip.start();
}
catch (Exception e) {
}
}
}
Now I have different Actions which are starting the timer for this class. Is there a way to hand over an parameter to the AarmTask()? Or can you think of an workaround without adding multiple AlarmTask() classes?