December 2, 201510 yr THIS TUTORIAL WILL BE REWRITTEN AS PART OF: https://osbot.org/forum/topic/115124-explvs-scripting-101/ Edited June 10, 20178 yr by Explv
December 2, 201510 yr This will help noobs like me and Keven mayne but I hope it doesnt drop my items @ GE
December 2, 201510 yr Author Nice job, but I do think most use builders though. No one learns by using a builder :xdoge:
December 2, 201510 yr 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
December 24, 201510 yr 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, 201510 yr by Dora
December 24, 201510 yr Author 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
March 23, 20169 yr 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.
March 23, 20169 yr Author 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, 20169 yr by Explv
March 24, 20169 yr Why are you reading a GUI tutorial noob Bc someone followed it and were having issues
March 24, 20169 yr // 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, 20169 yr by Psvxe
March 25, 20169 yr Author // 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, 20169 yr by Explv
March 25, 20169 yr 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
Create an account or sign in to comment