java - JFrame等待用户输入
问题描述
我有一个程序,我需要通过 Jframe 窗口从用户那里获取输入。它就像一个 while 循环,我在其中调用 Jframe 窗口并从用户那里获取输入。但是 JFrame 窗口不会等待输入并运行循环,直到它应该运行的最后一次并且只有在那里等待输入。
我想让 Jframe 窗口在 while 循环的每次迭代中等待输入。有没有办法做到这一点?
...
/**
* Create the frame.
*/
public Janela3(KieSession kSession) {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 462, 447);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
kSession.setGlobal("J3", this);
contentPane.setLayout(null);
JPanel panelMain = new JPanel();
panelMain.setBackground(new Color(248, 148, 6));
panelMain.setBounds(0, 0, 448, 44);
contentPane.add(panelMain);
tituloJanela = new JLabel();
tituloJanela.setFont(new Font("Tahoma", Font.BOLD, 24));
tituloJanela.setForeground(new Color(255, 255, 255));
panelMain.add(tituloJanela);
kSession.setGlobal("TJ3", tituloJanela);
JPanel childPugh = new JPanel();
childPugh.setBounds(0, 44, 448, 364);
...
}
解决方案
如果我是正确的,您有一个 while 循环,您可以在其中获取用户输入,但如果还没有输入,循环可能不会继续?目前您提供的信息太有限,无法给出具体答案,但我会试一试。
您可以通过使用另一个等待输入的 while 循环来解决这个问题。检查下面的“伪半真实代码”。
input = getInput();
while (input == null)
{
input = getInput();
}
推荐阅读
- ruby-on-rails - 如何在heroku上更频繁地运行rails rake任务超过10分钟?
- grails - Grails 不知道如何获取异常
- c# - 在 ASP.NET 中保留 HttpContext.Current 的同时并行化同步任务
- java - 如何在 Vaadin Flow 上保存和显示自定义图像?
- sql - SQL 循环帮助。循环不停止
- django - 我非常简单的 Django 表单没有将值传递给另一个视图
- java - 如何使用 UnboundID LDAP SDK 检查 LDAP 用户帐户是否在 Java 中过期
- lua - 公民:/scripting/resource_init.lua:17:'then'附近的意外符号
- python - python manage.py dumpdata 访问被拒绝
- javascript - module.exports js文件中的所有函数