?
Solved

Timer Functions? (Equiv to setTimeout in JavaScript)

Posted on 2007-11-23
7
Medium Priority
?
487 Views
Last Modified: 2012-06-27
I would like to add a function to an existing class that does the following:

- Create a countdown for, say, 45 seconds
- If there is no active mouse movement in the applet, the countdown continues (45, 44, 43, etc)
- If there is any mouse movement, reset the timer back to 45 seconds

(lather, rinse, repeat)

I have NEVER coded in Java before, so I'm completely clueless here.  The less complicated the better.  My main goal here is to make sure the user is actively using the applet.  After so many seconds of inactivity, I want to redirect the user to a "timeout" page (say, timeout.htm).  

Anyone out there that can help me out?  

I am open to any and all suggestions & advice.  Thanks!
0
Comment
Question by:gameness
[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
  • 2
  • 2
  • +1
7 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 20341871
You need to add a MouseListener to the frame to detect mouse moves,
and a Timer  (java.util.Timer) in repeat state to check every now and then.
Read the JAVADOC.
;JOOP!
0
 

Author Comment

by:gameness
ID: 20343455
sciuriware,
Where can I find the JAVADOC?  LIke I said above, I've NEVER coded in Java so I have no idea what I'm doing. :\
0
 
LVL 9

Expert Comment

by:ysnky
ID: 20343592
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:ysnky
ID: 20343598
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 1000 total points
ID: 20344940
JAVADOC for JAVA 1.6.3:  https://sdlc1a.sun.com/ECom/EComActionServlet;jsessionid=E43D76EC90DBAC9604DC165F19B7F560

It's 53 Mb, but it will be your bible! Expand it in a safe place (270 Mb) and execute the index.htm  ........................

;JOOP!
0
 

Assisted Solution

by:avanworld
avanworld earned 1000 total points
ID: 20346900
You may need to implement MouseMotionListener Interface instead as it contains two methods

void mouseDragged(MouseEvent me) -> called multiple times when mouse is dragged
void mouseMoved(MouseEvent me) -> called multiple times as the mouse is moved

On the other hand MouseListener Interface defines five methods which may not be of relevant to you

void mouseClicked(MouseEvent me)
void mouseEntered(MouseEvent me)
void mouseExited(MouseEvent me)
void mousePressed(MouseEvent me)
void mouseReleased(MouseEvent me)

Also there is another interface MouseWheelListener Interface

void mouseWheelMoved(MouseWheelEvent mwe)

There are also KeyListener interface but it is beyond the scope of this discussion

You can make your applet and javascript talk each other in that case you no need to implement Timer you can directly use the setTimeOut function of javascript

References:-

http://java.sun.com/products/plugin/1.3/docs/jsobject.html
http://en.wikipedia.org/wiki/LiveConnect
http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/livecon.htm
http://wp.netscape.com/eng/mozilla/3.0/handbook/plugins/
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:LiveConnect

Just Google LiveConnect you will find lot of resources
0
 

Expert Comment

by:avanworld
ID: 20347938
For using Timers in Swing application you can have a look at the following URL

http://java.sun.com/products/jfc/tsc/articles/timer/

It contains a demo source code as well. Hope it helps
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 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