• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Loop

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic