I'm having trouble getting this while loop to stop and look for a new input. Obviously the while loop is infinite because I don't get new input. I know this is easy but I'm still stuck

here is my while loop

while (guessInt != randInt){
    setPrevGuess(guessInt);
    guessInt = Integer.parseInt(GuessGame.numberField.getText());
	if (guessInt != randInt){
		if (guessInt > prevGuess ){
			guessGame.setBlueBackground();	
			setMessage(new JTextField("You're getting colder"));
		}
		if (guessInt < prevGuess ){
			guessGame.setRedBackground();	
			setMessage(new JTextField("You're getting warmer"));
		}
	}	
			
}

and I need to grap new information from a JButton in a different class

JButton guessButton = new JButton("Guess");
GuessHandler guessHandler = new GuessHandler();
guessHandler.setGuessGame(this);
guessButton.addActionListener(guessHandler);
guessFrameContainer.add(guessButton);

Can anyone please help this idiot?

Recommended Answers

All 2 Replies

If you are using a Swing Form to get Input then I would suggest dropping the while loop altogether because your actionPerformed() method will be called whenever your user clicks on the GuessButton and you can perform all the necessary processing then.

I was wondering about that this morning, I hit the button to call it but I thought I was going to have to put a listener or something back in the loop for the button, but you're right, I won't need the while at all...

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.