Reputation: 608
This is the Scenario.
I have Code which intiates a Alram when an error is encountered.
AudioAlarm t = new AudioAlarm(song);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Awake");
t.start();
setRunnung(true);
JOptionPane.showMessageDialog(null, "Alarm ...", "Alarm", JOptionPane.OK_OPTION);
AudioAlarm.setLoop(false);
System.out.println("Alarm Acknowledged ...");
I would like to re-design this logic in this manner,
If the Alarm is unacknowledged by the user over a period of time say 2 min, it turn off and message msg dialog should disappear.
How can I Obtain this?
I am able to Stop the Alram, but unable to dispose the dialog without the user pressing "OK"
Upvotes: 0
Views: 758
Reputation: 691635
To do what you want, you should:
JOptionPane
instance using one of its constructorscreateDialog
on this option pane to get a dialog containing this option panejavax.swing.Timer
instance in order to fire an action event after 2 minutesUpvotes: 1
Reputation: 52185
I do not know if what you are after can be done, but can't you instead replicate the JOptionPane as a JFrame and dispose of that one? You can find how to close a JFrame on this Previous SO Post:
If you want the GUI to behave as if you clicked the "X" then you need to dispatch a windowClosing Event to the Window. The "ExitAction" from Closing An Application allows you to add this functionality to a menu item or any component that uses Actions easily.
Upvotes: 0