| | |
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 26 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 |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows





