Solved

Timer Functions? (Equiv to setTimeout in JavaScript)

Posted on 2007-11-23
7
475 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 159
github account with ecipse 1 47
sql import cannot be resolved jsp 3 17
Java: anonymous class 4 16
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

813 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

11 Experts available now in Live!

Get 1:1 Help Now