Kelve
Kelve

Reputation: 137

JFrame wait for user's input

I have a program which i need to get input from the user through a Jframe window. Its like a while loop, where i invoke the Jframe window and get input from the user. But the JFrame window doesnt wait for input and run the loop until the last time it should run and only there waits for input.

I would like to make the Jframe window wait for input at each iteration of the while loop. Is there any way to do this ?

...

/**
 * 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);
    ...




}

Upvotes: 1

Views: 296

Answers (1)

Vallas
Vallas

Reputation: 503

If I'm correct, you have a while loop in which you get user input but the loop may not continue if there is no input yet? Currently the information you provide is too limited to give a concrete answer but I'll give it a shot.

You could solve this by using another while loop that waits for input. Check 'the pseudo-semi-real code' below.

input = getInput();
while (input == null)
{
   input = getInput();
}

Upvotes: 1

Related Questions