Click here to Skip to main content
15,917,997 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to know how to make a loop in java that keeps going until you click a button.

What I have tried:

I looked up some stuff and tried to figure it out.
Posted
Updated 17-Jul-17 15:40pm
Comments
Richard MacCutchan 11-Jun-17 11:48am    
If the logic of this question is not clear then you need to go back to your study guides.

Just a simple hint:

if(jButton1.getModel().isPressed())
 {
    //code
 }
else
{
   // loop code
}
 
Share this answer
 
v2
The above solution gives an answer if you are using Swing.

However, if you are using JavaFX, you could utilize something like this:

if(event.getCode() == KeyCode.Key) {
//enter code here
//Key is supposed to specify what key you want pressed
}

Also if you are using LibGDX, the following can be done:

if(Gdx.input.isKeyPressed(Keys.Key) {
//Place code here
//Key is supposed to specify what key you want pressed
}

Hope this helped!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900