July 27, 201510 yr 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.
July 27, 201510 yr GUI g = new GUI(); onStart() { g.setVisible(true); while (g.isVisible()) { sleep(400); } }
July 27, 201510 yr Author 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...
July 27, 201510 yr 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!"); }
July 27, 201510 yr 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.
July 27, 201510 yr 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.
July 27, 201510 yr 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
July 27, 201510 yr 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.
July 27, 201510 yr 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"?
July 27, 201510 yr 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.
July 27, 201510 yr 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.
July 28, 201510 yr 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
July 28, 201510 yr what if you press start, how would you "close it"? Dispose() Edited July 28, 201510 yr by Psvxe
Create an account or sign in to comment