Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://download.oracle.com/javase/6/docs/api/javax/swing/Timer.html"><code>javax.swing.Timer</code></a> has an initial delay; just set it to <code>60 * 60 * 1000</code>. Your <code>actionPerformed()</code> will be called an hour after invoking <code>start()</code>.</p> <p>Addendum: Here's an example of a button that hide's it's enclosing window for a specified period of time.</p> <pre><code>import java.awt.EventQueue; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.Timer; /** @see http://stackoverflow.com/questions/4373493 */ public class TimerFrame extends JFrame { private void display() { this.setTitle("TimerFrame"); this.setLayout(new GridLayout(0, 1)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.add(new TimerButton("Back in a second", 1000)); this.add(new TimerButton("Back in a minute", 60 * 1000)); this.add(new TimerButton("Back in an hour", 60 * 60 * 1000)); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true); } /** A button that hides it's enclosing Window for delay ms. */ private class TimerButton extends JButton { private final Timer timer; public TimerButton(String text, int delay) { super(text); this.addActionListener(new StartListener()); timer = new Timer(delay, new StopListener()); } private class StartListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { TimerFrame.this.setVisible(false); timer.start(); } } private class StopListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { timer.stop(); TimerFrame.this.setVisible(true); } } } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { new TimerFrame().display(); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload