HunterRS Posted July 27, 2015 Share Posted July 27, 2015 I have built a gui class using windowsbuilder in eclipse, my problem is that I can figure out how to call the class in the onStart method and also wait on the activation of the onLoop method untill a press of a button in the gui. p.s. my java knowlage is extremely basic as you can understand. Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 27, 2015 Share Posted July 27, 2015 GUI g = new GUI(); onStart() { g.setVisible(true); while (g.isVisible()) { sleep(400); } } Quote Link to comment Share on other sites More sharing options...
HunterRS Posted July 27, 2015 Author Share Posted July 27, 2015 GUI g = new GUI(); onStart() { g.setVisible(true); while (g.isVisible()) { sleep(400); } } how do I make sure that the user have selected an item? cuz if i just do sleep it may not work some times... Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 27, 2015 Share Posted July 27, 2015 how do I make sure that the user have selected an item? cuz if i just do sleep it may not work some times... Within GUI (textbox as an example) if (textBox.getText().isEmpty()) { JOptionPane.showMessageDialog(null, "You must fill out this text box first!"); return; } The return; will stop execution of the method. I personally have a boolean in my main class, guiWait, which I then set from true to false when the GUI has applied the settings. I do something like this: GUI g = new GUI(); public static boolean guiWait = true; onStart() { g.setVisible(true); while (guiWait) { sleep(400); } } //GUI //Button actionPerformed if (conditionsMet) { ArbitraryScriptClass.guiWait = false; } else { JOptionPane.showMessageDialog(null, "You must select a preset or define a monster first!"); } 1 Quote Link to comment Share on other sites More sharing options...
Jack Posted July 27, 2015 Share Posted July 27, 2015 while (g.isVisible()) { sleep(400); } } While this is very common, you WILL get laughed if you do this in any sort of formal setting (School assignment, work, etc). The proper way would be to implement an Interface that serves as a callback for when the gui is done. 1 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 27, 2015 Share Posted July 27, 2015 While this is very common, you WILL get laughed if you do this in any sort of formal setting (School assignment, work, etc). The proper way would be to implement an Interface that serves as a callback for when the gui is done. :^) p.s. my java knowlage is extremely basic as you can understand. Quote Link to comment Share on other sites More sharing options...
Apaec Posted July 27, 2015 Share Posted July 27, 2015 to have the GUI settings saved to your main class, you should put an action listener on your start button. Google how to do this , or in window builder right click the component and go action>actionPerformed then just statically send your GUI variables to your desired location before putting a setVisible(false) in the action listener for the start button. Not a neat way of doing it but does the job just fine and is pretty basic apa Quote Link to comment Share on other sites More sharing options...
Psvxe Posted July 27, 2015 Share Posted July 27, 2015 to have the GUI settings saved to your main class, you should put an action listener on your start button. Google how to do this , or in window builder right click the component and go action>actionPerformed then just statically send your GUI variables to your desired location before putting a setVisible(false) in the action listener for the start button. Not a neat way of doing it but does the job just fine and is pretty basic apa Why would you make the gui invisible rather than closing it? Doesn't make sense. Quote Link to comment Share on other sites More sharing options...
Precise Posted July 27, 2015 Share Posted July 27, 2015 Why would you make the gui invisible rather than closing it? Doesn't make sense. what if you press start, how would you "close it"? Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 27, 2015 Share Posted July 27, 2015 what if you press start, how would you "close it"? I always personally leave my GUIs open so people can screenshot them for bug reports, but I believe you can set it to close the GUI without ending the script. Quote Link to comment Share on other sites More sharing options...
Precise Posted July 27, 2015 Share Posted July 27, 2015 I always personally leave my GUIs open so people can screenshot them for bug reports, but I believe you can set it to close the GUI without ending the script. you can. Quote Link to comment Share on other sites More sharing options...
Apaec Posted July 28, 2015 Share Posted July 28, 2015 Why would you make the gui invisible rather than closing it? Doesn't make sense. You can do either, but personally I make them invisible so should it be required, you can just show it again without recreating it but to be honest it doesn't really matter Quote Link to comment Share on other sites More sharing options...
Psvxe Posted July 28, 2015 Share Posted July 28, 2015 (edited) what if you press start, how would you "close it"? Dispose() Edited July 28, 2015 by Psvxe Quote Link to comment Share on other sites More sharing options...