Ragboys is back Posted June 15, 2018 Share Posted June 15, 2018 (edited) I've been working on my first GUI but I have NO idea on how to start my script. I'm a little mind-kcuf'd right now since I'm working with two classes, the GUI and the Main where everything happens. I know I should be using a listener for my button "start" but then I have no idea what should be inside the action-listener body. Should I call the onLoop() method? If so, how? I have searched a lot of GUI tutorials on this forums & google in general but cant seem to find anything. Would love to get any help possible. Edited June 15, 2018 by Ragboys is back Quote Link to comment Share on other sites More sharing options...
d0zza Posted June 15, 2018 Share Posted June 15, 2018 Have a global boolean called started that you set to be true inside the action-listener body. Then have an if (started) check in your onLoop. Quote Link to comment Share on other sites More sharing options...
yfoo Posted June 15, 2018 Share Posted June 15, 2018 private void openGUI(){ GUI gui = new GUI(this); try{ while(gui.isGuiActive()){ //1 sleep(500); } } catch (InterruptedException e){ log(e.toString()); } } confirmButton.addActionListener(e -> { guiActive = false; //2 frame.dispose(); } }); One implementation is under onStart() you could put some code like above. 1. In your GUI class a boolean value (that is retrieved via gui.isGuiActive()) denotes whether the user is finished with the gui (pressed start). Until then, wait. 2. you denote that a user is finished with the Gui by flipping said boolean value to false when your start button is pressed (in your listener for your start button). Basically you are delaying the conclusion of onStart() until the user is finished with the GUI. Then you proceed to onLoop() afterwards. Quote Link to comment Share on other sites More sharing options...
Team Cape Posted June 15, 2018 Share Posted June 15, 2018 11 minutes ago, PayPalMeRSGP said: private void openGUI(){ GUI gui = new GUI(this); try{ while(gui.isGuiActive()){ //1 sleep(500); } } catch (InterruptedException e){ log(e.toString()); } } confirmButton.addActionListener(e -> { guiActive = false; //2 frame.dispose(); } }); One implementation is under onStart() you could put some code like above. 1. In your GUI class a boolean value (that is retrieved via gui.isGuiActive()) denotes whether the user is finished with the gui (pressed start). Until then, wait. 2. you denote that a user is finished with the Gui by flipping said boolean value to false when your start button is pressed (in your listener for your start button). Basically you are delaying the conclusion of onStart() until the user is finished with the GUI. Then you proceed to onLoop() afterwards. Small, but important addition: Your button should also set the GUI to not be visible. This is done by frame.setVisible(false) in the context of the code that @PayPalMeRSGP wrote Quote Link to comment Share on other sites More sharing options...
Canidae Posted June 15, 2018 Share Posted June 15, 2018 5 hours ago, d0zza said: Have a global boolean called started that you set to be true inside the action-listener body. Then have an if (started) check in your onLoop. I recommend you not using this. If the script list is not refreshed, the static fields will keep their values. So as soon as someone stops the script and starts it again without refreshing the list, it will start instantly and probably crash. Quote Link to comment Share on other sites More sharing options...
d0zza Posted June 15, 2018 Share Posted June 15, 2018 35 minutes ago, Canidae said: I recommend you not using this. If the script list is not refreshed, the static fields will keep their values. So as soon as someone stops the script and starts it again without refreshing the list, it will start instantly and probably crash. I never said it should be static? 1 Quote Link to comment Share on other sites More sharing options...
Canidae Posted June 15, 2018 Share Posted June 15, 2018 (edited) 8 hours ago, d0zza said: I never said it should be static? Java doesn't really have global variables. So as soon as someone refers to a "global variable" in Java, people will interpret it as a static variable because they share some of their properties. Edited June 15, 2018 by Canidae Quote Link to comment Share on other sites More sharing options...
d0zza Posted June 16, 2018 Share Posted June 16, 2018 (edited) 7 hours ago, Canidae said: Java doesn't really have global variables. So as soon as someone refers to a "global variable" in Java, people will interpret it as a static variable because they share some of their properties. Yes but scripting for osbot does have global variables. Edited June 16, 2018 by d0zza Quote Link to comment Share on other sites More sharing options...
Canidae Posted June 16, 2018 Share Posted June 16, 2018 6 hours ago, d0zza said: Yes but scripting for osbot does have global variables. I don't get what you mean? Quote Link to comment Share on other sites More sharing options...
d0zza Posted June 16, 2018 Share Posted June 16, 2018 2 minutes ago, Canidae said: I don't get what you mean? You can have global variables in a script Quote Link to comment Share on other sites More sharing options...
Canidae Posted June 16, 2018 Share Posted June 16, 2018 (edited) 3 minutes ago, d0zza said: You can have global variables in a script What do you mean with global variables then? They don't exist in Java and you also said your meaning of global variables aren't (public) static variables. What is it then? The only thing you can do in Java is having public classes with a public static variable in it to make it look like it's some sort of global variable. Edited June 16, 2018 by Canidae Quote Link to comment Share on other sites More sharing options...
d0zza Posted June 16, 2018 Share Posted June 16, 2018 3 minutes ago, Canidae said: What do you mean with global variables then? They don't exist in Java and you also said your meaning of global variables aren't (public) static variables. What is it then? The only thing you can do in Java is having public classes with a public static variable in it to make it look like it's some sort of global variable. Open up any script you've written, then go inside the script manifest but not inside any method, type int foo = 1; and there's your global variable. Quote Link to comment Share on other sites More sharing options...
Canidae Posted June 16, 2018 Share Posted June 16, 2018 11 minutes ago, d0zza said: Open up any script you've written, then go inside the script manifest but not inside any method, type int foo = 1; and there's your global variable. I have no clue what you mean. Quote Link to comment Share on other sites More sharing options...