在单击按钮之前,如何创建循环 [英] How do I make a loop that keeps going until you click a button
本文介绍了在单击按钮之前,如何创建循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何在java中循环,直到你点击一个按钮。
什么我试过了:
我查了一些东西并试图搞清楚。
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.
推荐答案
只是一个简单的提示:
Just a simple hint:
if(jButton1.getModel().isPressed())
{
//code
}
else
{
// loop code
}
如果你使用Swing,上面的解决方案给出了答案。
但是,如果你使用JavaFX,你可以使用这样的东西:
if(event.getCode()== KeyCode.Key){
//在此处输入代码
//密钥应该是指定你想按什么键
}
另外如果你使用LibGDX,可以做以下事情:
if(Gdx.input.isKeyPressed(Keys.Key){
//这里的代码
//键应该指定你想按什么键
}
希望这有帮助!
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!
这篇关于在单击按钮之前,如何创建循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文