Solved

Java swing app timeout/exit after 3minutes

Posted on 2008-09-30
2
616 Views
Last Modified: 2013-11-23
Hi All,

I have a java swing app with different buttons and features. I need assistance in writing a thread to:
Have the java app timeout and exit the java app after three minutes of not pressing any buttons in the app.

Another words, if the app goes unused for 3 minutes then exit. (Not just at the start of the app, but at any time during the use of the app that three minures have gone by since they have clicked anything.

Thank you for you help in advance.

tom
0
Comment
Question by:Costellot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
wwnosal earned 125 total points
ID: 22609045
You can write a class e.g: Timer (see code snippet):

Then in main you can start it like this:
  Thread t = new Thread(new Timer());
   t.start ( );

In function "click" of each button that should keep application running you should call static method resetCounter()

Thats all ;-)
hope this helps
public class Timer implements Runnable {
  private static int max = 180;
 
  private static int counter = 0;
 
  /**
   * @see java.lang.Runnable#run()
   */
  public void run ( ) {
    while ( counter < max ) {
      // just keep running
      try {
        Thread.sleep ( 1000 );
        counter++;
        System.out.println ("---W--");
      }
      catch ( InterruptedException e ) {
        // won't handle
      }
    }
    System.exit ( 0 );
  }
 
  public static void resetCounter ( ) {
    counter = 0;
  }  
 
}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Debugging a PHP Web Application 2 130
How to install eclipse SCADA on Linux Debian? 4 167
Eclipse versons - run configurations 2 86
Eclipse XML hightlightning 5 63
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question