Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Loop" Watch "Loop" New topic
Author

Loop

Tom Schuman
Greenhorn

Joined: Dec 30, 2004
Posts: 18
I have a problem.
I want an integer to rise with 1 every second while key is pressed and when i relase it it would stop rising. I have tried doing this without success. I believe I should use a loop or something but I have no idea how to have a 1 sec pause in the loop neither how I get it to start/stop when I press a key. Please explain thorougly i just started java.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

You may have noticed that no one is responding to your question. The reason no one is answering your question is the same reason Fred discussed when you asked a similar question last month in your other thread. Once again you have provide little information as to what you have done to solve your own problem, and where you are stuck. Instead you have asked for someone to give you a through explanation of how to solve the problem.

As Fred explained, people here volunteer their time because they like helping people learn and use Java. However that kindness does not extend so far as to solve someone's problem from start to finish.

I will happily point you in the direction you need to go to solve this problem. While on its surface this looks like an easy task, it involves using some interminate to advanced level classes and techniques. A loop is not the way to solve this problem. Have you looked at the EventListener interface and the topic of listeners as Stan and Fred suggested in your last thread? If not, you will want to do some research on them. You can start with the Java API Docs and the Sun Tutorial on Event Listeners. Those will get you started, but you will likely need to read a more advanced treaties on the subject as well. In addition to listeners, you will also want to learn about Threads for this problem. Threads are very powerful. Java makes them easy to use (especially compared to other languages). But threads are full of potential pitfalls if not understood and used properly.
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Originally posted by Tom Schuman:
I have a problem.
I want an integer to rise with 1 every second while key is pressed and when i relase it it would stop rising. I have tried doing this without success. I believe I should use a loop or something but I have no idea how to have a 1 sec pause in the loop neither how I get it to start/stop when I press a key. Please explain thorougly i just started java.


OK, show us what you have written and we will tell you where you are going wrong. As you have just started learning Java, this is the best way to learn rather than getting the code off someone else.
 
 
subject: Loop