Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Window to submit data freezing when created inside a mouse clicked event?  RSS feed

 
Louis Lewis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm trying to right a GUI in swing, and as part of my program, I want to open a secondary window out of the main window when a mouse clicks on the main window. Then, once I click a button on the secondary window, I want that window to close and submit data to the main window (like an info form). I have almost figured out how to do this, except for one problem. By putting a variable inside my form window called "ready," and then in my main window running a loop that constantly checks if ready is true and doesn't proceed until its true, I can create the form window, modify the values in it (currently just one value called "difficulty" that's modified by a jSlider), and then when i click the "begin" button, ready is changed to true, the form window closes, and the main window can proceed. However, when I try to put the while loop checking the ready variable inside a mouseClicked method in the main window, the form window freezes when it opens, and you can't see any of its content or modify it in any way (you can't even close it). Does anyone know how to fix this, or an easier way to do what I'm trying to do? Here is my code:





 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Louis Lewis wrote:Hello, I'm trying to right a GUI in swing, and as part of my program, I want to open a secondary window out of the main window when a mouse clicks on the main window. Then, once I click a button on the secondary window, I want that window to close and submit data to the main window (like an info form).


The usual way you would do this would be to make the secondary window a JDialog. Creating the JDialog blocks all access to the original GUI, at least for a modal JDialog. Then when the user clicks on the "OK" button in the JDialog, control returns to the original GUI which can extract data from the JDialog using ordinary getter methods. You're familiar with dialog boxes, you've seen them in all kinds of software. What you've done is much harder to make work because the secondary window you produce isn't modal. I wouldn't recommend doing it that way at all.
 
Louis Lewis
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I used a JDialog class, and it worked! I didn't realize that the code in the main window would automatically pause until the jDialog window is closed, but it does, so everything works now.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to hear that. Sounds like you got it straightened out pretty quickly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!