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.

Load Pictures from Resources to GUI

Featured Replies

I know the first post on this page is pinned and says how to use the Resource folder... but  I am still stuck.  I also know there is a Data folder but I don't want that unless I have to.  I can make my GUI run as a stand alone JAR without OSBot and images load from resources, but once the client tries to do it the pics are null.  It is about 14 pics so I do not want to pull from imgur.  Checking the JAR in the OSBot/Scripts folder I see the resources are built into the JAR.

Folder structure:

Script.jar

-->resources/

      -->images.png

-->src/

      -->Main

      -->GUI

Code in GUI:

public ImageIcon pic;

public class GUI{

  public void setImages(){
      this.pic = new ImageIcon(getClass().getResource("images.png")); **** error on this line in GUI *****
  }

}

   Code in Main:

...

public void onStart() {
	GUI gui = new GUI();
      try {
      gui.setImages(); ***** error on this line in main *****
      } catch (IOException e) {
      e.printStackTrace();
      }
      try {
      gui.GUI();
      } catch (IOException e) {
      e.printStackTrace();
      }

}

 

Script getScriptResourceAsStream - This loads resources relative to the entry of the script
Script getDataResourceAsStream - This loads resources relative to the entry of the OSBot data directory

Here are two examples so you get an idea:

 

ztfC9pq.png

 

x5gt9d6.png

 

Of course please ensure you are still following the existing SDN resources folder rules. 

https://osbot.org/forum/topic/140109-osbot-254-resource-loading/

  • Author
7 minutes ago, Chris said:

this is how I read in my plugin

 


this.image = ImageIO.read(script.getScriptResourceAsStream("resources/" + imgName));

 

But the JLabel requires an ImageIcon not just BufferedImage or Image?

4 minutes ago, Ace99 said:

But the JLabel requires an ImageIcon not just BufferedImage or Image?

My other comment just shows the loading of resources. you can read how you want

  • Author
24 minutes ago, Chris said:

My other comment just shows the loading of resources. you can read how you want

Yeah thanks I saw that after I replied.  I had my folder structure off for sure.  I don't get null error anymore so I think it found the image and I have JLabel issues to work out.

Much appreciated!

  • Author

@Chris I am still getting errors and have been stuck for hours! Shame its a GUI error of all things to be stuck on.  Ill put my file structure, code, and error if you have time to review (or anyone)! I have been tunnel visioning this so hard I may be missing something obvious.

 

image.png.9e69336e2d69c24bbb4761dd1eb0e2d2.pngimage.png.314956b263d609d23fe302872feae2c0.png

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

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

import java.io.IOException;


@ScriptManifest(author = "Ace99", name = "Test GUI", logo = "", version = 1.0 , info = "")

public class Main extends Script {

    Image guam;

    @Override
    public void onStart() throws InterruptedException {

        try {
            this.guam = ImageIO.read(getScriptResourceAsStream("resources/Guam_potion_(unf).png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        JFrame frame = new JFrame("Does this work?" );
        ImageIcon guamPic = new ImageIcon(guam);
        JLabel picture = new JLabel();
        picture.setIcon(guamPic);
        picture.setBounds(10,10,200,200);
        frame.add(picture);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setLayout(null);
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.setSize(430, 300);
        frame.setVisible(true);

         /*
        if (guam != null) {
            log("found it");
        } else {
            log("waiting around");
            sleep(15000);
        }
         */

        super.onStart();
    }

    @Override
    public int onLoop() throws InterruptedException {


        return 500;
    }
}

 

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.