0

Block input while JDialog is open

I'm trying to make an RPG game in java and I wanted to show a PNG image. The problem is all game is on the console (it is a text-base game) except the image that I open with JDialog, when I open the image, the consoles freezes (what I wanted to do), but if I write on the console while frozen, the scanner will catch what I typed and when I close the Image will run what I typed. I tried to reset the scanner but it didn't work. Here's an exemple: What I wanted to do: (Show image) User type: hello (User closes image) Type something: User type: bye You typed bye, right? What happens: (Show image) User type: hello (User closes image) Type something: hello You typed hello, right? Here's what I'm doing: https://code.sololearn.com/c1OU22Xs7mrZ

14th Jan 2022, 3:54 PM
Tomás Ribeiro
Tomás Ribeiro - avatar
3 Respostas
0
try this stdin.skip(".*"); System.out.print("Type something: ");
15th Jan 2022, 8:33 PM
zemiak
0
The stdin.skip(".*") didn't work alone, but it'll work if you do this: stdin.skip(".*"); stdin = new Scanner("System.in"); System.out.print("Type something: "); But I don't know how safe it is to do this...
15th Jan 2022, 9:34 PM
Tomás Ribeiro
Tomás Ribeiro - avatar
0
it should be ok
16th Jan 2022, 4:15 AM
zemiak