Ace99 Posted April 7, 2020 Share Posted April 7, 2020 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(); } } Quote Link to comment Share on other sites More sharing options...
Chris Posted April 7, 2020 Share Posted April 7, 2020 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: Of course please ensure you are still following the existing SDN resources folder rules. https://osbot.org/forum/topic/140109-osbot-254-resource-loading/ 1 Quote Link to comment Share on other sites More sharing options...
Ace99 Posted April 7, 2020 Author Share Posted April 7, 2020 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? Quote Link to comment Share on other sites More sharing options...
Chris Posted April 7, 2020 Share Posted April 7, 2020 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 Quote Link to comment Share on other sites More sharing options...
Ace99 Posted April 7, 2020 Author Share Posted April 7, 2020 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! 1 Quote Link to comment Share on other sites More sharing options...
Ace99 Posted April 8, 2020 Author Share Posted April 8, 2020 @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. 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; } } Quote Link to comment Share on other sites More sharing options...