Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JFrame等待用户';s输入_Java_Swing_Input_Jframe - Fatal编程技术网

Java JFrame等待用户';s输入

Java JFrame等待用户';s输入,java,swing,input,jframe,Java,Swing,Input,Jframe,我有一个程序,我需要通过Jframe窗口从用户那里获取输入。 它就像一个while循环,在这里我调用Jframe窗口并从用户那里获取输入。但是JFrame窗口不会等待输入,直到最后一次应该运行循环时才运行循环,只有在那里等待输入 我想让Jframe窗口在while循环的每次迭代中等待输入。有没有办法做到这一点 ... /** * Create the frame. */ public Janela3(KieSession kSession) { setDefaultCloseOpe

我有一个程序,我需要通过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();
}

你能减少屏幕上的代码量吗?我不确定是否也需要。好的,我已经做了。请阅读并相应地增强您的问题。我不知道你先发布了什么,但现在你的问题没有包含太多与你的问题相关的内容。