Explv Posted December 2, 2015 Share 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 Quote Link to comment Share on other sites More sharing options...
Chris Posted December 2, 2015 Share Posted December 2, 2015 This will help noobs like me and Keven mayne but I hope it doesnt drop my items @ GE 2 Quote Link to comment Share on other sites More sharing options...
KEVzilla Posted December 2, 2015 Share Posted December 2, 2015 Nice job, but I do think most use builders though. Quote Link to comment Share on other sites More sharing options...
Explv Posted December 2, 2015 Author Share Posted December 2, 2015 Nice job, but I do think most use builders though. No one learns by using a builder :xdoge: Quote Link to comment Share on other sites More sharing options...
Apaec Posted December 2, 2015 Share 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 Quote Link to comment Share on other sites More sharing options...
gorgas8 Posted December 8, 2015 Share Posted December 8, 2015 (edited) . Edited January 15, 2016 by gorgas8 Quote Link to comment Share on other sites More sharing options...
Animos Posted December 8, 2015 Share Posted December 8, 2015 thanks gave me an A on my java class!!!!! Quote Link to comment Share on other sites More sharing options...
Kalispel Posted December 24, 2015 Share 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 Quote Link to comment Share on other sites More sharing options...
Explv Posted December 24, 2015 Author Share 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 Quote Link to comment Share on other sites More sharing options...
Valkyr Posted March 23, 2016 Share 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 Quote Link to comment Share on other sites More sharing options...
Explv Posted March 23, 2016 Author Share 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 Quote Link to comment Share on other sites More sharing options...
Valkyr Posted March 24, 2016 Share Posted March 24, 2016 Why are you reading a GUI tutorial noob Bc someone followed it and were having issues 2 Quote Link to comment Share on other sites More sharing options...
Psvxe Posted March 24, 2016 Share 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 Quote Link to comment Share on other sites More sharing options...
Explv Posted March 25, 2016 Author Share 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 Quote Link to comment Share on other sites More sharing options...
Psvxe Posted March 25, 2016 Share 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 Quote Link to comment Share on other sites More sharing options...