Mr Pro Pop Posted September 22, 2016 Share Posted September 22, 2016 (edited) Eclipse Windows Builder Gui Tutorial Hello guys, Welcome to my first tutorial.Today I am going to show you how to make JFrames for osbot using eclipse windows builder. Everything is going to be detailed and in high quality with clear pictures & text.Firstly, You will need to download eclipse, Here is the official website, I would suggest downloading this version (Eclipse IDE For Jave EE Developers). First Step -> Here is how to setup windows builder tool with eclipse! Firstly, Go to the taskbar/menu and click on "Help" --> "Install New Software".Will open a new window, Click "Add" and type this link into the location field and confirm, Select the "windows builder" and install they are over 14 tools! While the installation process it will give you a warning message just ignore it and once it finishes installing it will ask you to restart eclipse!https://dl.bintray.com/zaunerc/p2/org.eclipse.windowbuilder.p2_site/latest/ Spoiler for -> How to use Eclipse Windows Builder So now we need to create a new project and a class if we don't have one. Now to create a new JFrame file we will need to right click the project and create a ( New --> Other ) 1-) just type in the wizard/search box filed "JFrame". or2-) select "Windows builder --> Swing Designer" folder you will see the JFrame and other tools, Click on the JFrame. Now go to the design mode, Here is how to switch! and a look of my project/created classes! Designing Panel In the structure components, You will see ContentPane, Click into it and go to the "properties --> layout" and change it to absolute for your own custom design otherwise, The layout they chose won't let you drag the item where ever you want, Only spots, Check here! I have changed the ContentPane to MyScript name from the variable option.Now I will start adding an example design, Let's say a combo box and a button,To add values inside the combo box you need you click the model option and add your values! Now this is the most important part of the whole tutorial. [Main Work] We will start grabbing the code of our design and adding it into our script and make an action listener to check if the button is selected and which combo box option is selected, We will need to copy the JComboBox and the JButton, Follow me! public JFrame() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 406, 155); ScriptName = new JPanel(); ScriptName.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(ScriptName); ScriptName.setLayout(null); JComboBox comboBox = new JComboBox(); comboBox.setModel(new DefaultComboBoxModel(new String[] {"Select An Option", "Demo 1", "Demo 2", "Demo 3"})); comboBox.setBounds(30, 34, 124, 44); ScriptName.add(comboBox); JButton btnStart = new JButton("Start"); btnStart.setBounds(236, 40, 89, 33); ScriptName.add(btnStart); } Put this below public class main extends Script { private JPanel ScriptName; Import this in your script class import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; Make a new method inside your script, Follow! public void JFrame() { JFrame ScriptName; ScriptName = new JFrame(); ScriptName.setTitle("title"); //your own title //add your panel size here the setbounds ScriptName.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ScriptName.getContentPane(); ScriptName.setLayout(null); //Paste your JCmboBox here! //Now paste your Button code here ScriptName.getContentPane().add(btnStart); ScriptName.setVisible(true); //makes the button appearing when the script start btnStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ScriptName.setVisible(false); //disappear when clicking on the button ScriptName.dispose(); String chat = comboBox.getSelectedItem().toString(); //gets the selected item in the combo box log(chat); } }); } In your created JFrame file you will have the panel size which will look like this setBounds(100, 100, 406, 155); Change it to ScriptName.setBounds(100, 100, 406, 155); //ofc with your own bounds and then paste it below your method in the script file Now go in your onStart() method and add this JFrame(); And now in your onExit method, You can add this! ScriptName.setVisible(false); //so it removes the panel (disappearing - not showing) if you clicked stop in the script! Now we have finished everything lets test it out! Works, Anyways we don't need the JFrame file we created you can delete it, We just used to grab the designs of it!Anyways here is a better method to understand the action listener, We coulddothis.. //instead of that String chat = comboBox.getSelectedItem().toString(); log(chat); //you could do String treename = comboBox.getSelectedItem().toString(); RS2Object tree = objects.closest(treename); And in your loop/method adding this tree.interact("Chop"); Here is how my final code looks like. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "Mr Pro Pop", info = "JFrame", logo = "", name = "JFrame", version = 1) public class main extends Script { private JPanel ScriptName; public void JFrame() { JFrame ScriptName; ScriptName = new JFrame(); ScriptName.setTitle("title"); ScriptName.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ScriptName.setBounds(100, 100, 406, 155); ScriptName.getContentPane(); ScriptName.setLayout(null); JComboBox comboBox = new JComboBox(); comboBox.setModel(new DefaultComboBoxModel(new String[] { "Select An Option", "Demo 1", "Demo 2", "Demo 3" })); comboBox.setBounds(30, 34, 124, 44); ScriptName.add(comboBox); JButton btnStart = new JButton("Start"); btnStart.setBounds(236, 40, 89, 33); ScriptName.add(btnStart); ScriptName.getContentPane().add(btnStart); ScriptName.setVisible(true); btnStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub ScriptName.setVisible(false); ScriptName.dispose(); String chat = comboBox.getSelectedItem().toString(); log(chat); } }); } public void onStart() { JFrame(); } public int onLoop() throws InterruptedException { return 0; } } Now we are done guys, I hope you have enjoyed with my tutorial and learnt how to make a JFrames, If so please support my post by a like and a comment, I would really be happy and appreciate! This is my first tutorial.Sorry if i have done anything wrong or did an mistake / forgot something.If you have any questions or a requested tutorial/project, Please let me know. Thank you guys for reading. Best regards, Mr Pro Pop! Edited September 24, 2016 by Mr Pro Pop 4 Quote Link to comment Share on other sites More sharing options...
venetox Posted September 23, 2016 Share Posted September 23, 2016 Lol, I instinctively tried to close the OSBot ad in your screenshot.Great tutorial, this will definitely help newbies.Also, quick note, You don't actually need to move all the code in JFrame class, instead, rename the JFrame.java and all relevant references to its name as a class to for example SettingsGUI then create an instance of the SetttingsGUI in your Main.java private SettingsGUI gui; public void onStart() { gui = new SettingsGUI(); gui.setVisible(true); } That is how I do settings gui's in my scripts, if you want to do stuff on clicking buttons etc, you would also want to pass your SettingsGUI the current script.This is how my SettingsGUI.java is in my HGuildMiner for example (created by window builder) package com.harleydaun.osrs.hguildminer.core; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JButton; import javax.swing.JCheckBox; /** * The gui to change settings, created by Eclipse WindowBuilder */ public class SettingsGUI extends JFrame { private static final long serialVersionUID = 1100271528597140602L; private JPanel contentPane; private Main theScript; /** * Create the frame. */ public SettingsGUI(Main main) { theScript = main; setTitle(theScript.getName() + " " + theScript.getVersion() + " by " + theScript.getAuthor()); setBounds(100, 100, 170, 109); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JCheckBox chckbxMineMithril = new JCheckBox("Mine Mithril"); chckbxMineMithril.setBounds(25, 7, 97, 23); contentPane.add(chckbxMineMithril); JButton btnStart = new JButton("Start"); btnStart.addActionListener(e -> { theScript.selectedMineArea = Locations.AREA_MINING_GUILD; theScript.selectedMinePos = Locations.POS_MINING_GUILD; theScript.selectedBankArea = Locations.AREA_FALADOR_EAST_BANK; theScript.selectedMineString = "MG"; theScript.mineMithril = chckbxMineMithril.isSelected(); theScript.mineCoal = true; theScript.startScript(); }); btnStart.setBounds(25, 37, 99, 23); contentPane.add(btnStart); } } Then in my Main.java I have private SettingsGUI gui; // Instance of the GUI. public void onStart() { gui = new SettingsGUI(this); //various checks to see if to show the gui yet .. .. gui.setVisible(true); } Quote Link to comment Share on other sites More sharing options...
Mr Pro Pop Posted September 24, 2016 Author Share Posted September 24, 2016 (edited) aha thanks @@venetox Now we have it added by 2 methods hehe lolol xD "Lol, I instinctively tried to close the OSBot ad in your screenshot." Lmao Edited September 24, 2016 by Mr Pro Pop Quote Link to comment Share on other sites More sharing options...
shaba123 Posted May 27, 2018 Share Posted May 27, 2018 Thanks for this very helpful, cant find many other in detail gui guides on the forum Quote Link to comment Share on other sites More sharing options...
liverare Posted May 27, 2018 Share Posted May 27, 2018 I wouldn't shove your GUI code in with your script code, otherwise it'll get unwieldy. You can download my glassblowing script to see how I implemented my GUI: 1 Quote Link to comment Share on other sites More sharing options...
alkku15 Posted June 11, 2018 Share Posted June 11, 2018 (edited) yo how to do this with a textfield? cant get it to work for some reason tried something like this JTextField txtnameOfNpc = new JTextField(); txtnameOfNpc.setHorizontalAlignment(SwingConstants.CENTER); txtnameOfNpc.setText("(name of npc to kill)"); txtnameOfNpc.setBounds(10, 11, 214, 20); ScriptName.add(txtnameOfNpc); txtnameOfNpc.setColumns(10); txtnameOfNpc.addActionListener(e -> chat = (String) txtnameOfNpc.getSelectedText().toString()); then at graphics i tried to print the String chat to the screen, didnt work... then tried it the way you put it there txtnameOfNpc.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ScriptName.setVisible(false); //disappear when clicking on the button ScriptName.dispose(); String chat = txtnameOfNpc.getSelectedText().toString(); //gets the selected item in the combo box log(chat); } }); Edited June 11, 2018 by alkku15 Quote Link to comment Share on other sites More sharing options...