Solved

Timer Functions? (Equiv to setTimeout in JavaScript)

Posted on 2007-11-23
7
472 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:ysnky
ID: 20343598
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 250 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 21
Unable to open debugger port in Intellij idea 6 140
json example 39 131
Java passing arguments (type error) 2 48
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

911 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

17 Experts available now in Live!

Get 1:1 Help Now