June 15, 20187 yr 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, 20187 yr by Ragboys is back
June 15, 20187 yr 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.
June 15, 20187 yr 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.
June 15, 20187 yr 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
June 15, 20187 yr 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.
June 15, 20187 yr 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?
June 15, 20187 yr 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, 20187 yr by Canidae
June 16, 20187 yr 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, 20187 yr by d0zza
June 16, 20187 yr 6 hours ago, d0zza said: Yes but scripting for osbot does have global variables. I don't get what you mean?
June 16, 20187 yr 2 minutes ago, Canidae said: I don't get what you mean? You can have global variables in a script
June 16, 20187 yr 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, 20187 yr by Canidae
June 16, 20187 yr 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.
June 16, 20187 yr 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.
Create an account or sign in to comment