Deceiver Posted May 5, 2015 Share Posted May 5, 2015 (edited) Hey everyone, I was wondering if some of you could help me out with something that is probably easy. I have basic knowledge of Java, and GUI making, etc Swing, JavaFX through Eclipse's window builder and such. Now, probably about 99% of the scripts have a GUI with options and such, what I'm wondering is how would I would incorporate actions; E.G, I have a start button on my GUI, after all the settings are to my liking, I'd click start to obviously start the script. I realize the actionhandler method(s) are used there, etc. But would I need to make the GUI class within the, say, TestMiner.java (The main file of the script extending the Script class of the API). Would that allow me to start the script when the handler is called when the Start button is clicked? Or if someone could provide small snippet(s) to this, that would be great. Or, if you need a better explanation, I'd be happy to provide another one. Edited May 5, 2015 by Deceiver Quote Link to comment Share on other sites More sharing options...
jacksonadams861 Posted May 5, 2015 Share Posted May 5, 2015 (edited) I go like this: boolean GUI_COMPLETE = false; exampleGUI gui = new exampleGUI(); @Override public void onStart() { gui.setVisible(true); } @Override public int onLoop() throws InterruptedException { if (GUI_COMPLETE) { //normal script loop; } return 50; // The amount of time in milliseconds before the loop // starts // over } public class exampleGUI extends JFrame { //gui code with an actionlistener on the start button which sets GUI_COMPLETE to true, and disposes the GUI. } Edited May 5, 2015 by jacksonadams861 1 Quote Link to comment Share on other sites More sharing options...
Apaec Posted May 5, 2015 Share Posted May 5, 2015 Probably neatest to have your entire GUI code in a seperate class. A simple way you can do it is using an actionlistener for your start button, reading the current options on the UI and assigning them to variables. Then directly statically (i know, ew, but ye) modifying the main classes set variables for that bot instance to reflect what was chosen in the UI. let me kno if i didnt answer ur question 1 Quote Link to comment Share on other sites More sharing options...
Deceiver Posted May 5, 2015 Author Share Posted May 5, 2015 I go like this: boolean GUI_COMPLETE = false; exampleGUI gui = new exampleGUI(); @Override public void onStart() { gui.setVisible(true); } @Override public int onLoop() throws InterruptedException { if (GUI_COMPLETE) { //normal script loop; } return 50; // The amount of time in milliseconds before the loop // starts // over } public class exampleGUI extends JFrame { //gui code with an actionlistener on the start button which sets GUI_COMPLETE to true, and disposes the GUI. } Thanks. Probably neatest to have your entire GUI code in a seperate class. A simple way you can do it is using an actionlistener for your start button, reading the current options on the UI and assigning them to variables. Then directly statically (i know, ew, but ye) modifying the main classes set variables for that bot instance to reflect what was chosen in the UI. let me kno if i didnt answer ur question Yeah, I'd prefer a separate class for it as well, and I'll look into that, thanks. Quote Link to comment Share on other sites More sharing options...
Tom Posted May 6, 2015 Share Posted May 6, 2015 I go like this: boolean GUI_COMPLETE = false; exampleGUI gui = new exampleGUI(); @Override public void onStart() { gui.setVisible(true); } @Override public int onLoop() throws InterruptedException { if (GUI_COMPLETE) { //normal script loop; } return 50; // The amount of time in milliseconds before the loop // starts // over } public class exampleGUI extends JFrame { //gui code with an actionlistener on the start button which sets GUI_COMPLETE to true, and disposes the GUI. } This isnt exactly the best option either, you don't "need" to instantiate the GUI like that at all really, you can just put new GUI(this), and from within the GUI's constructor set it to visible. Should also be invoked, not just initialized in the onStart 1 Quote Link to comment Share on other sites More sharing options...