Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Explv's Dank GUI Tutorial

Featured Replies

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.

 

Good input, as some might want better coding practices. Good guide none-the-less.

hey could u show us how to add a text box in the GUI? like for an AIO combat script it would need a box to type the names of the monsters. Thanks

  • 1 month later...

Hello man, I've never worked with IntelliJ in my life so sorry for asking this, I've made a form but how do I add this to the script?

@Explv

Edited by GaetanoH

  • Author

Hello man, I've never worked with IntelliJ in my life so sorry for asking this, I've made a form but how do I add this to the script?

@Explv

 

When you create a form in IntelliJ it also creates a binding class. For example if you named your form "GUI" there will also be a Java class called "GUI" that is created.

 

In the form view you will see that the there is a top level container, which is a JPanel. The first thing to do is name this JPanel, you can call it "mainPanel" or something like that.

 

Then make the binding class extend JFrame. JFrame is the main window for a swing GUI.

 

Your GUI class should look something like:

public class GUI extends JFrame {

    JPanel mainPanel;
    // some other variables
}

Now, you will need to add the JPanel (mainPanel) that you created in the form view, to this gui:

public class GUI extends JFrame {

    JPanel mainPanel;
    // some other variables

    public GUI(){
        add(mainPanel);
    }
}

Now, in your script when you want to display this GUI you can simply do:

@ScriptManifest(...)
public class YourScript extends Script {

    private GUI gui;

    @Override
    public void onStart() {
        gui = new GUI();
        gui.setVisible(true);
    }

    @Override
    public int onLoop() throws InterruptedException {
       return 0;
    }

    @Override
    public void onExit() {
        if(gui != null) {
            gui.setVisible(false);
            gui.dispose();
        }
    }
}

When you create a form in IntelliJ it also creates a binding class. For example if you named your form "GUI" there will also be a Java class called "GUI" that is created.

 

In the form view you will see that the there is a top level container, which is a JPanel. The first thing to do is name this JPanel, you can call it "mainPanel" or something like that.

 

Then make the binding class extend JFrame. JFrame is the main window for a swing GUI.

 

Your GUI class should look something like:

public class GUI extends JFrame {

    JPanel mainPanel;
    // some other variables
}
Now, you will need to add the JPanel (mainPanel) that you created in the form view, to this gui:

public class GUI extends JFrame {

    JPanel mainPanel;
    // some other variables

    public GUI(){
        add(mainPanel);
    }
}
Now, in your script when you want to display this GUI you can simply do:

@ScriptManifest(...)
public class YourScript extends Script {

    private GUI gui;

    @Override
    public void onStart() {
        gui = new GUI();
        gui.setVisible(true);
    }

    @Override
    public int onLoop() throws InterruptedException {
       return 0;
    }

    @Override
    public void onExit() {
        if(gui != null) {
            gui.setVisible(false);
            gui.dispose();
        }
    }
}

 

Holy shit thanks for this fast response, I get it! You'll get credits when I finish my script :)

 

When you create a form in IntelliJ it also creates a binding class. For example if you named your form "GUI" there will also be a Java class called "GUI" that is created.

 

In the form view you will see that the there is a top level container, which is a JPanel. The first thing to do is name this JPanel, you can call it "mainPanel" or something like that.

 

Then make the binding class extend JFrame. JFrame is the main window for a swing GUI.

 

Your GUI class should look something like:

public class GUI extends JFrame {

    JPanel mainPanel;
    // some other variables
}

Now, you will need to add the JPanel (mainPanel) that you created in the form view, to this gui:

public class GUI extends JFrame {

    JPanel mainPanel;
    // some other variables

    public GUI(){
        add(mainPanel);
    }
}

Now, in your script when you want to display this GUI you can simply do:

@ScriptManifest(...)
public class YourScript extends Script {

    private GUI gui;

    @Override
    public void onStart() {
        gui = new GUI();
        gui.setVisible(true);
    }

    @Override
    public int onLoop() throws InterruptedException {
       return 0;
    }

    @Override
    public void onExit() {
        if(gui != null) {
            gui.setVisible(false);
            gui.dispose();
        }
    }
}

 

I can't seem to get it to work, when I use .setVisible(true), it can't find the symbol.

Ok, I got it a working a little bit, I needed to add, setVisible in the constructor of the GUI not in my script, the problem is I have a lot of NullPointerExceptions

 


java.lang.NullPointerException
	at java.awt.Container.addImpl(Container.java:1093)
	at java.awt.Container.add(Container.java:1005)
	at javax.swing.JFrame.addImpl(JFrame.java:567)
	at java.awt.Container.add(Container.java:417)
	at GHWoodcutterGUI.<init>(GHWoodcutterGUI.java:12)
	at GHWoodcutter.onStart(GHWoodcutter.java:39)
	at org.osbot.rs07.event.ScriptExecutor.iiIIiiIIiI(lk:265)
	at org.osbot.rs07.event.ScriptExecutor.start(lk:158)
	at org.osbot.qB.run(tm:137)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
[INFO][Bot #1][05/12 01:56:48 PM]: Terminating script GHWoodcutter...

Edited by GaetanoH

  • Author

 

Ok, I got it a working a little bit, I needed to add, setVisible in the constructor of the GUI not in my script, the problem is I have a lot of NullPointerExceptions

 

java.lang.NullPointerException
	at java.awt.Container.addImpl(Container.java:1093)
	at java.awt.Container.add(Container.java:1005)
	at javax.swing.JFrame.addImpl(JFrame.java:567)
	at java.awt.Container.add(Container.java:417)
	at GHWoodcutterGUI.<init>(GHWoodcutterGUI.java:12)
	at GHWoodcutter.onStart(GHWoodcutter.java:39)
	at org.osbot.rs07.event.ScriptExecutor.iiIIiiIIiI(lk:265)
	at org.osbot.rs07.event.ScriptExecutor.start(lk:158)
	at org.osbot.qB.run(tm:137)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
[INFO][Bot #1][05/12 01:56:48 PM]: Terminating script GHWoodcutter...

 

Can you post your GUI code?

import javax.swing.*;
import java.awt.*;

/**
 * Created by Gaetano on 12/05/16.
 */
public class WoodcutterGUI extends JFrame{
    private JPanel panel;

    public WoodcutterGUI() {
        super("GHWoodcutter");
        add(panel);
        setVisible(true);
    }
}

It's probably something stupid, haven't made a GUI in ages.

  • Author
import javax.swing.*;
import java.awt.*;

/**
 * Created by Gaetano on 12/05/16.
 */
public class WoodcutterGUI extends JFrame{
    private JPanel panel;

    public WoodcutterGUI() {
        super("GHWoodcutter");
        add(panel);
        setVisible(true);
    }
}

It's probably something stupid, haven't made a GUI in ages.

You are using Intellij Form Designer though right?

private JPanel panel;
If that JPanel is not bound to the JPanel in Intelij Form Designer, then when you call:
add(panel);
It will throw a NullPointerException.

Here is a graphical example of what I meant in my previous comment.

Firs you have to provide a name for the top level JPanel in the .form view:

bZq6UVK.png

Then in the bound Java class with the same name you do:

import javax.swing.*;

public class GUI extends JFrame {
    private JPanel mainPanel;

    public GUI(){
        add(mainPanel);
        setTitle("Whatever");
        setVisible(true);
    }
}
This code works perfectly fine.

Don't forget you will also need to set a preferred size on your JFrame otherwise it will be very small:

import javax.swing.*;
import java.awt.*;

public class GUI extends JFrame {
    private JPanel mainPanel;

    public GUI(){
        add(mainPanel);
        setTitle("Whatever");
        setVisible(true);
        setPreferredSize(new Dimension(400, 400));
    }
}
One more important thing.

If you are uploading this script to the SDN, and you are using Intellij Form Designer, you will need to make Intellij compile the .form into Java code in your class.

If you don't do this, when you copy over your GUI class file, none of your GUI code will be there, and it will break.

To do this you need to go to:

File -> Settings -> Editor -> GUI Designer

And change the option "Generate GUI into:"'s value to Java source code.

2EWCzFf.png

And then make the project

Edited by Explv

You are using Intellij Form Designer though right?

private JPanel panel;
If that JPanel is not bound to the JPanel in Intelij Form Designer, then when you call:
add(panel);
It will throw a NullPointerException.

Here is a graphical example of what I meant in my previous comment.

Firs you have to provide a name for the top level JPanel in the .form view:

bZq6UVK.png

Then in the bound Java class with the same name you do:

import javax.swing.*;

public class GUI extends JFrame {
    private JPanel mainPanel;

    public GUI(){
        add(mainPanel);
        setTitle("Whatever");
        setVisible(true);
    }
}
This code works perfectly fine.

Don't forget you will also need to set a preferred size on your JFrame otherwise it will be very small:

import javax.swing.*;
import java.awt.*;

public class GUI extends JFrame {
    private JPanel mainPanel;

    public GUI(){
        add(mainPanel);
        setTitle("Whatever");
        setVisible(true);
        setPreferredSize(new Dimension(400, 400));
    }
}
One more important thing.

If you are uploading this script to the SDN, and you are using Intellij Form Designer, you will need to make Intellij compile the .form into Java code in your class.

If you don't do this, when you copy over your GUI class file, none of your GUI code will be there, and it will break.

To do this you need to go to:

File -> Settings -> Editor -> GUI Designer

And change the option "Generate GUI into:"'s value to Java source code.

2EWCzFf.png

And then make the project

 

 

I'll try it out tonight, thanks for the good tutorial :)

You are using Intellij Form Designer though right?

private JPanel panel;
If that JPanel is not bound to the JPanel in Intelij Form Designer, then when you call:
add(panel);
It will throw a NullPointerException.

Here is a graphical example of what I meant in my previous comment.

Firs you have to provide a name for the top level JPanel in the .form view:

bZq6UVK.png

Then in the bound Java class with the same name you do:

import javax.swing.*;

public class GUI extends JFrame {
    private JPanel mainPanel;

    public GUI(){
        add(mainPanel);
        setTitle("Whatever");
        setVisible(true);
    }
}
This code works perfectly fine.

Don't forget you will also need to set a preferred size on your JFrame otherwise it will be very small:

import javax.swing.*;
import java.awt.*;

public class GUI extends JFrame {
    private JPanel mainPanel;

    public GUI(){
        add(mainPanel);
        setTitle("Whatever");
        setVisible(true);
        setPreferredSize(new Dimension(400, 400));
    }
}
One more important thing.

If you are uploading this script to the SDN, and you are using Intellij Form Designer, you will need to make Intellij compile the .form into Java code in your class.

If you don't do this, when you copy over your GUI class file, none of your GUI code will be there, and it will break.

To do this you need to go to:

File -> Settings -> Editor -> GUI Designer

And change the option "Generate GUI into:"'s value to Java source code.

2EWCzFf.png

And then make the project

 

 

Is there any way to do it after I've created the form? I have my Woodcutter and the GUI setup but forgot to check Generate into Java source code...

  • Author

Is there any way to do it after I've created the form? I have my Woodcutter and the GUI setup but forgot to check Generate into Java source code...

 

Yes, to generate the source code just 'make' the project.

 

Hit Ctrl F9

 

or

 

Go to Build -> Make Project

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.