Solved

Timer Functions? (Equiv to setTimeout in JavaScript)

Posted on 2007-11-23
7
478 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
Technology Partners: 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!

 
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

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
How to get all the API from website? 11 127
Way to decrease size of apk file 9 108
sql import cannot be resolved jsp 3 75
learn programming 8 69
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…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

749 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