| | |
Timer - Problem
![]() |
•
•
Join Date: Oct 2009
Posts: 4
Reputation:
Solved Threads: 0
Hi
The timer works fine when you run it alone, there is a set time befor it exits, 3seconds. But when you open it from the previous window, the timer doesn't start or exit. (The purpose of this is on the previous frame of GUI, the user clicks the exit button, a picture is displayed then quits).
Here's the code.
The timer works fine when you run it alone, there is a set time befor it exits, 3seconds. But when you open it from the previous window, the timer doesn't start or exit. (The purpose of this is on the previous frame of GUI, the user clicks the exit button, a picture is displayed then quits).
Here's the code.
Java Syntax (Toggle Plain Text)
import java.util.Timer; import java.util.TimerTask; /** * * @author Mike */ public class ExitJoke extends javax.swing.JFrame { Timer timer; public ExitJoke(int seconds) { this.setLocationRelativeTo(null); timer = new Timer(); timer.schedule(new RemindTask(), seconds * 1000); } class RemindTask extends TimerTask { public void run() { System.out.println ( "Time's up!" ) ; timer.cancel(); //Terminate the timer thread System.exit(0); } } /** Creates new form ExitJoke */ public ExitJoke() { initComponents(); } private void btnJokeActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } public static void main(String args[]) { System.out.println ( "About to schedule task." ) ; new ExitJoke ( 2 ) ;//Time in seconds. System.out.println ( "Task scheduled." ) ; java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ExitJoke().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnJoke; private javax.swing.JPanel jPanel1; // End of variables declaration }
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 53
0
#2 24 Days Ago
Java Syntax (Toggle Plain Text)
System.exit(0);
find another solution e.g. setting the status window on the invisible
![]() |
Other Threads in the Java Forum
- Previous Thread: How can an Action event cause a property change in the parent?
- Next Thread: problem..plz help
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card character class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting researchinmotion scanner se server service set sms software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows





