Jump to content

Eclipse Windows Builder Gui [Tutorial]


Mr Pro Pop

Recommended Posts

                                                                                   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/


9f6518da39d2ed67c498f5cb3b2acd88.gif


 

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". or
2-) 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!

c3c630dea33830cf9b815dffc446fce0.gif


 
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!

76a62ff0b921c332ad0cbd232a9305b6.gif
 
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!

 
5a413704278475717a25a2537433da59.gif
 


 
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!


 
29018b40bdc0df02acf637c21c42215b.gif

 
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 could
dothis..
 

//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 by Mr Pro Pop
  • Like 4
Link to comment
Share on other sites

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);
    }
Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...

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 by alkku15
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...