Solved

Timer Functions? (Equiv to setTimeout in JavaScript)

Posted on 2007-11-23
7
469 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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
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
Comment Utility
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
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:ysnky
Comment Utility
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 250 total points
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now