Explv Posted December 2, 2015 Posted December 2, 2015 (edited) THIS TUTORIAL WILL BE REWRITTEN AS PART OF: https://osbot.org/forum/topic/115124-explvs-scripting-101/ Edited June 10, 2017 by Explv 12
Chris Posted December 2, 2015 Posted December 2, 2015 This will help noobs like me and Keven mayne but I hope it doesnt drop my items @ GE 2
KEVzilla Posted December 2, 2015 Posted December 2, 2015 Nice job, but I do think most use builders though.
Explv Posted December 2, 2015 Author Posted December 2, 2015 Nice job, but I do think most use builders though. No one learns by using a builder :xdoge:
Apaec Posted December 2, 2015 Posted December 2, 2015 Nice, but this can all be achieved in about 10 seconds with a window builder for those curious, here's the windowbuilder pro plugin for eclipse: http://www.eclipse.org/windowbuilder/download.php apa 4
gorgas8 Posted December 8, 2015 Posted December 8, 2015 (edited) . Edited January 15, 2016 by gorgas8
Kalispel Posted December 24, 2015 Posted December 24, 2015 (edited) Why do you dispose of it in onExit()? Wouldn't that get rid of it when the script stops and not when you press the start button? Edited December 24, 2015 by Dora
Explv Posted December 24, 2015 Author Posted December 24, 2015 Why do you dispose of it in onExit()? Wouldn't that get rid of it when the script stops and not when you press the start button? Yes. When the user stops the script the JFrame is disposed of if it exists. The JFrame is also hidden when the user starts the script: startButton.addActionListener(e -> { // This code is called when the user clicks the button started = true; // Set the boolean variable started to true gui.setVisible(false); // Hide the GUI }); See the line gui.setVisible(false); // Hide the GUI 1
Valkyr Posted March 23, 2016 Posted March 23, 2016 Why declare a JFrame within the script class? Separate it. public class GUI extends JFrame { public GUI() { setTitle("GUI); ... pack(); setVisible(true); } } Instantiate within the script class public class ShitScript extends Script { private GUI gui; ... @Override public void onStart() { gui = new GUI(); } @Override public void onExit() { if(gui != null) gui.dispose(); } ... } This way, you can manage your GUI without having to trawl through a ton of unrelated code in the script class. 2
Explv Posted March 23, 2016 Author Posted March 23, 2016 (edited) Why declare a JFrame within the script class? Separate it. public class GUI extends JFrame { public GUI() { setTitle("GUI); ... pack(); setVisible(true); } } Instantiate within the script class public class ShitScript extends Script { private GUI gui; ... @Override public void onStart() { gui = new GUI(); } @Override public void onExit() { if(gui != null) gui.dispose(); } ... } This way, you can manage your GUI without having to trawl through a ton of unrelated code in the script class. Why are you reading a GUI tutorial noob Edited March 23, 2016 by Explv
Valkyr Posted March 24, 2016 Posted March 24, 2016 Why are you reading a GUI tutorial noob Bc someone followed it and were having issues 2
Psvxe Posted March 24, 2016 Posted March 24, 2016 (edited) // Declare two constants for width and height of the GUI final int GUI_WIDTH = 350, GUI_HEIGHT = 75; // Get the size of the screen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // Calculating x and y coordinates final int gX = (int) (screenSize.getWidth() / 2) - (GUI_WIDTH / 2); final int gY = (int) (screenSize.getHeight() / 2) - (GUI_HEIGHT / 2);Or to set a size to exactly your liking gui#setSize(int width, int heigth) //size of the gui; gui#setLocationRelativeTo(null); //centers the guiNice guide, will help the noobs. good job! Edited March 24, 2016 by Psvxe 1
Explv Posted March 25, 2016 Author Posted March 25, 2016 (edited) // Declare two constants for width and height of the GUI final int GUI_WIDTH = 350, GUI_HEIGHT = 75; // Get the size of the screen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // Calculating x and y coordinates final int gX = (int) (screenSize.getWidth() / 2) - (GUI_WIDTH / 2); final int gY = (int) (screenSize.getHeight() / 2) - (GUI_HEIGHT / 2);Or to set a size to exactly your liking gui#setSize(int width, int heigth) //size of the gui; gui#setLocationRelativeTo(null); //centers the guiNice guide, will help the noobs. good job! Nice, I wrote this a while ago :P definitely more succinct to use setLocationRelativeTo(null) Edited March 25, 2016 by Explv 1
Psvxe Posted March 25, 2016 Posted March 25, 2016 Nice, I wrote this a while ago definitely more succinct to use setLocationRelativeTo(null) Still a good read for beginners who want to make a GUI