Supercharger Posted October 22, 2014 Share Posted October 22, 2014 Hey Guys, So haven't prorammed or scripted for a long time and excited to get back into it and learning it agian. I want to implement a working GUI and I don't know how. I've made a good GUI with WindowsBuilder in eclipse but I don't know how to program it into make it work.. Would anybody be able to help me out? Also, http://osbot.org/forum/topic/60921-areapositionmyplayer/ I'm looking to add checking if the play is an area like this thread, but I'm curious to know how to I make the area like, what are the coordinates I see the Method as Area(Int, Int, Int, Int). How is that composed of? Like... What is the first, second, third, and fourth int? Link to comment Share on other sites More sharing options...
The Hero of Time Posted October 22, 2014 Share Posted October 22, 2014 add scripters here on skype ;p Link to comment Share on other sites More sharing options...
Joseph Posted October 22, 2014 Share Posted October 22, 2014 (edited) Make sure your facing north. The area is bottom left corner. Then to right corner. So it's (min x, min y, max x, max y) Please ha the right import Edited October 22, 2014 by josedpay Link to comment Share on other sites More sharing options...
Supercharger Posted October 22, 2014 Author Share Posted October 22, 2014 Make sure your facing north. The area is bottom left corner. Then to right corner. So it's (min x, min y, max x, max y) Please ha the right import Thanks mate, now.. What about the GUI. You have any idea? Link to comment Share on other sites More sharing options...
Swizzbeat Posted October 22, 2014 Share Posted October 22, 2014 Create a new GUI instance in your script class...? Link to comment Share on other sites More sharing options...
Pug Posted October 22, 2014 Share Posted October 22, 2014 (edited) here is some more detail on area's if you have a area you want to make imagine a square has four edges, you need to diagonally oppersite edges to make that square in your script. Look at the image below: I have wrote down two sets of X & Y co'ordinates. The top left and the top right. So top left you have X = 1318 and Y = 3238. Bottom right we have X = 1320 and Y = 3240. Now you have your box or area. We need to put this into our script. We first need to declare the area. This can put put at the top of your script under: public class YourScriptName extends Script { // put area declaration here so what code do we put? ok so look at the code below then i'l explain it. Area areaName = new Area(1234,1234,1234,1234); ok so look at the code above. We have Area which you should always put first, its saying you are going to declare a new area. then you see ' areaName ' this is going to be the name of your area so you could call it something like ' bankArea ' or ' cuttingArea ' just make sure its one word no spaces. You can use underscores if you wish. Use basic variable naming conventions. After the name of our area we have four co'ordinates 1234 1234 1234 1234 these are the X and Y co'ordinates. If we use the picture above i showed you as an example it would be: Area areaName = new Area(1320,3240,1318,3238); notice i put the bottom right set first, then the top right set. This is how i was told to do it when i learnt and its worked for me in all my scripts, there may be other ways as Josed said above. So now you have delcared your area at the top of your script you need to use that code. So lets have another example. Imagine if you will that you want to know if your player is in a bank. You can use something like this: if(areaName.contains(myPlayer()) { // do something } I have used the same area name as before so not to confuse you but you put the name of your area. then a full stop and then you can test that area for players, variables, objects etc. I have chosen to use myPlayer() as we wanted to check if our player was within an area. if you need any more help post back here ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ SECOND POST FOR YOU. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ also here is an example gui class is just whipped up for you, i tried to comment most of it so you can follow whats happening, any question post here. import java.awt.Font; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(name="script name", author="author", info="1.00", logo="", version=1.00D) public final class gui extends Script { Thegui GUI; String sourca = "Pick A Rune"; String[] theSource = { "Pick A Rune", "Air", "Mind" , "Water", "Earth", "Fire", "Body", "Cosmic", "Nature", "Law" }; // image url of the logo for your gui private final Image title = getImage("http://s30.postimg.org/5dg0503c1/title_fw.png"); // grab image from the web method private Image getImage(String url) { try { return ImageIO.read(new URL(url)); } catch (IOException e) {} return null; } // on start public final void onStart() { GUI = new Thegui(); // set gui visible on start GUI.setVisible(true); } public class Thegui extends JFrame { private JPanel contentPane; private JTextField txtAt; private JTextField textField; private JTextField textField_1; public Thegui() { setTitle("script name"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 436, 497); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); // add a logo JLabel pugLogo1 = new JLabel(new ImageIcon(title)); // set the location for the logo, X - Y - length in px - height in px pugLogo1.setBounds(60, 11, 320, 40); // add the logo to the pane contentPane.add(pugLogo1); // add a label JLabel lblMode = new JLabel("Mode:"); // set the location lblMode.setBounds(40, 77, 49, 24); // add the label to the pane contentPane.add(lblMode); // add a radio button JRadioButton rdbtnAbyss = new JRadioButton("Abyss"); // set the location rdbtnAbyss.setBounds(152, 77, 55, 23); // make it greyed out rdbtnAbyss.setVisible(false); // add the radio button to the pane contentPane.add(rdbtnAbyss); // add a combo box ( note the course is a array of items you wish to add to the combo box) final JComboBox comboBox = new JComboBox(theSource); // set the location comboBox.setBounds(101, 107, 120, 20); // add the combo box contentPane.add(comboBox); // add a checkbox final JCheckBox chckbxUseRuneEssence = new JCheckBox("Use Rune essence"); // set the location chckbxUseRuneEssence.setBounds(40, 137, 130, 23); // add check box to the pane contentPane.add(chckbxUseRuneEssence); // add a text field txtAt = new JTextField(); // set the text to show upon starting the gui txtAt.setText("30"); // set the location txtAt.setBounds(223, 267, 38, 20); // set the columns txtAt.setColumns(10); // add the text field to the pane contentPane.add(txtAt); // add a new button ( the start script button ) JButton btnStart = new JButton("Start"); // set the location btnStart.setBounds(10, 425, 404, 23); // add the button to the pane contentPane.add(btnStart); // action listener for runes comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if ((comboBox.getSelectedItem() == "Air")) { sourca = "Air"; textField_1.setEnabled(false); chckbxUseRuneEssence.setEnabled(true); txtAt.setEnabled(false); textField.setEnabled(false); } } }); // action listener for start button btnStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); } } @Override public int onLoop() throws InterruptedException { // if gui is not visible and gui choice is air runes then make air runes lol. // good practice to use gui is not visible so that script wont start till gui is closed. if ((!this.GUI.isVisible()) && (this.sourca.contains("Air"))) { } return 600; } } Edited October 22, 2014 by Pug 3 Link to comment Share on other sites More sharing options...
Swizzbeat Posted October 22, 2014 Share Posted October 22, 2014 here is some more detail on area's if you have a area you want to make imagine a square has four edges, you need to diagonally oppersite edges to make that square in your script. Look at the image below: I have wrote down two sets of X & Y co'ordinates. The top left and the top right. So top left you have X = 1318 and Y = 3238. Bottom right we have X = 1320 and Y = 3240. Now you have your box or area. We need to put this into our script. We first need to declare the area. This can put put at the top of your script under: public class YourScriptName extends Script{ // put area declaration here so what code do we put? ok so look at the code below then i'l explain it. Area areaName = new Area(1234,1234,1234,1234); ok so look at the code above. We have Area which you should always put first, its saying you are going to declare a new area. then you see ' areaName ' this is going to be the name of your area so you could call it something like ' bankArea ' or ' cuttingArea ' just make sure its one word no spaces. You can use underscores if you wish. Use basic variable naming conventions. After the name of our area we have four co'ordinates 1234 1234 1234 1234 these are the X and Y co'ordinates. If we use the picture above i showed you as an example it would be: Area areaName = new Area(1320,3240,1318,3238); notice i put the bottom right set first, then the top right set. This is how i was told to do it when i learnt and its worked for me in all my scripts, there may be other ways as Josed said above. So now you have delcared your area at the top of your script you need to use that code. So lets have another example. Imagine if you will that you want to know if your player is in a bank. You can use something like this: if(areaName.contains(myPlayer()){ // do something} I have used the same area name as before so not to confuse you but you put the name of your area. then a full stop and then you can test that area for players, variables, objects etc. I have chosen to use myPlayer() as we wanted to check if our player was within an area. if you need any more help post back here ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ SECOND POST FOR YOU. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ also here is an example gui class is just whipped up for you, i tried to comment most of it so you can follow whats happening, any question post here. import java.awt.Font;import java.awt.Image;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import java.net.URL;import javax.imageio.ImageIO;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JTextField;import javax.swing.border.EmptyBorder;import org.osbot.rs07.api.ui.Skill;import org.osbot.rs07.script.Script;import org.osbot.rs07.script.ScriptManifest;@ScriptManifest(name="script name", author="author", info="1.00", logo="", version=1.00D)public final class gui extends Script{ Thegui GUI; String sourca = "Pick A Rune"; String[] theSource = { "Pick A Rune", "Air", "Mind" , "Water", "Earth", "Fire", "Body", "Cosmic", "Nature", "Law" }; // image url of the logo for your gui private final Image title = getImage("http://s30.postimg.org/5dg0503c1/title_fw.png"); // grab image from the web method private Image getImage(String url) { try { return ImageIO.read(new URL(url)); } catch (IOException e) {} return null; } // on start public final void onStart() { GUI = new Thegui(); // set gui visible on start GUI.setVisible(true); } public class Thegui extends JFrame { private JPanel contentPane; private JTextField txtAt; private JTextField textField; private JTextField textField_1; public Thegui() { setTitle("script name"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 436, 497); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); // add a logo JLabel pugLogo1 = new JLabel(new ImageIcon(title)); // set the location for the logo, X - Y - length in px - height in px pugLogo1.setBounds(60, 11, 320, 40); // add the logo to the pane contentPane.add(pugLogo1); // add a label JLabel lblMode = new JLabel("Mode:"); // set the location lblMode.setBounds(40, 77, 49, 24); // add the label to the pane contentPane.add(lblMode); // add a radio button JRadioButton rdbtnAbyss = new JRadioButton("Abyss"); // set the location rdbtnAbyss.setBounds(152, 77, 55, 23); // make it greyed out rdbtnAbyss.setVisible(false); // add the radio button to the pane contentPane.add(rdbtnAbyss); // add a combo box ( note the course is a array of items you wish to add to the combo box) final JComboBox comboBox = new JComboBox(theSource); // set the location comboBox.setBounds(101, 107, 120, 20); // add the combo box contentPane.add(comboBox); // add a checkbox final JCheckBox chckbxUseRuneEssence = new JCheckBox("Use Rune essence"); // set the location chckbxUseRuneEssence.setBounds(40, 137, 130, 23); // add check box to the pane contentPane.add(chckbxUseRuneEssence); // add a text field txtAt = new JTextField(); // set the text to show upon starting the gui txtAt.setText("30"); // set the location txtAt.setBounds(223, 267, 38, 20); // set the columns txtAt.setColumns(10); // add the text field to the pane contentPane.add(txtAt); // add a new button ( the start script button ) JButton btnStart = new JButton("Start"); // set the location btnStart.setBounds(10, 425, 404, 23); // add the button to the pane contentPane.add(btnStart); // action listener for runes comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if ((comboBox.getSelectedItem() == "Air")) { sourca = "Air"; textField_1.setEnabled(false); chckbxUseRuneEssence.setEnabled(true); txtAt.setEnabled(false); textField.setEnabled(false); } } }); // action listener for start button btnStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); } } @Override public int onLoop() throws InterruptedException { // if gui is not visible and gui choice is air runes then make air runes lol. // good practice to use gui is not visible so that script wont start till gui is closed. if ((!this.GUI.isVisible()) && (this.sourca.contains("Air"))) { } return 600; } } You should really be using a boolean to determine whether the start button has been pushed (with an accessor, I hate when people make things static "because it works"). Checking for if the GUI is visible is a terrible choice, as you should always make decisions based on the source of truth (in this case the start button).Also, work on your variable names. "theSource" for an array of rune names makes no sense what so ever. Link to comment Share on other sites More sharing options...
Joseph Posted October 23, 2014 Share Posted October 23, 2014 You could separate both the gui class and script class. Create your gui then in the script class you would create a gui instance. With in the class you could create public methods they will help you return your data. Link to comment Share on other sites More sharing options...