Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • TaskScript GUI help


    Dude32

    Recommended Posts

    Hi everyone!

    I am new to the community and relatively new to scripting for OSRS. I have setup a taskScript that works quite well and I was wanting to expand on the script by adding a GUI with user input. I am using Intellij's Swing UI Designer to create the form, then writing the code to run this on the associated class and my taskScript. Whenever I try running this, I get the error in Dreambot:

    16:03:02: [WARN] This script's GUI is causing performance issues.

    Followed by an extremely long error of:

    Spoiler

    16:03:02: [ERROR] Swing threading error::
        org.pushingpixels.substance.api.UiThreadingViolationException: Swing component creation must be done on the Event Dispatch Thread. Try wrapping your method in SwingUtilities#invokeLater.
        at org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities.testComponentCreationThreadingViolation(SubstanceCoreUtilities.java)
        at org.pushingpixels.substance.internal.ui.SubstancePanelUI.createUI(SubstancePanelUI.java)
        at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:72)
        at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:276)
        at javax.swing.UIDefaults.getUI(UIDefaults.java:770)
        at javax.swing.UIManager.getUI(UIManager.java:1016)
        at javax.swing.JPanel.updateUI(JPanel.java:126)
        at javax.swing.JPanel.<init>(JPanel.java:86)
        at javax.swing.JPanel.<init>(JPanel.java:109)
        at javax.swing.JPanel.<init>(JPanel.java:117)
        at javax.swing.JRootPane.createGlassPane(JRootPane.java:546)
        at javax.swing.JRootPane.<init>(JRootPane.java:366)
        at javax.swing.JFrame.createRootPane(JFrame.java:286)
        at javax.swing.JFrame.frameInit(JFrame.java:267)
        at javax.swing.JFrame.<init>(JFrame.java:234)
        at GUI.ScriptGUI.Main(ScriptGUI.java:29)
        at Main.FishCook.onStart(FishCook.java:30)
        at org.dreambot.api.script.AbstractScript.run(AbstractScript.java)
        at java.lang.Thread.run(Thread.java:748)

     

    Could one of you help me understand why? (Sorry if this is a noob question, I have done some searching but couldn't find anything to fix this myself).

    Relevant source code below:

    TaskScript:

    Spoiler
    package Main;
    
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.impl.TaskScript;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.methods.skills.SkillTracker;
    import tasks.CookingTask;
    import tasks.*;
    import GUI.ScriptGUI;
    
    import java.awt.*;
    
    
    @ScriptManifest(author = "DB", name = "Fish Cook", version = 0.1, description = "Fish Cook", category = Category.FISHING)
    
    public class FishCook extends TaskScript {
    
       public static String status;
       public static boolean userInputGUI = false;
    
       @Override
       public void onStart() {
          status = "Starting script";
          SkillTracker.start(Skill.FISHING);
    
          /*addNodes(new FishingTask(), new ChoppingTask(), new CookingTask(), new DropTask());*/
          ScriptGUI.Main();
       }

    GUI Script

    Spoiler
    package GUI;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class ScriptGUI extends JFrame {
        private JPanel mainPanel;
        private JComboBox fishingTypeComboBox;
        private JButton playButton;
        private JComboBox locationComboBox;
        private JCheckBox powerFishing;
    
        public ScriptGUI(String title) {
            this.$$$setupUI$$$();
            this.setContentPane(this.mainPanel);
            this.setSize(450, 300);
            this.setDefaultCloseOperation(3);
            this.setVisible(true);
            this.pack();
            this.playButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                }
            });
        }
    
        public static void Main() {
            new JFrame("DB's FishCook Script v0.1");
        }
    }

    Image uploaded of the form designer.

     

    Many thanks in advance for any help :D

    Capture.JPG

    Link to comment
    Share on other sites

    Hey guys

    Quick update from me. I have got the GUI to appear now (see screenshot). I still have the errors in the console (including the extremely large one)

    18:29:35: [WARN] This script's GUI is causing performance issues.

    I think I need to do the SwingUtilities#invokeLater around my method but not sure exactly the context.

    Capture.JPG

    Link to comment
    Share on other sites

    Thank you so much @pakruojinis! I had been googling for the issue but it didn't find that page. I have now got it working without the errors.

     

    Incase others have the issue, I just want to point out the context I am using (As Intellij suggested some changes)

    TaskScript - Key part is the Try statement. This is what IntelliJ suggested.

    Spoiler
    package Main;
    
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.impl.TaskScript;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.methods.skills.SkillTracker;
    import tasks.CookingTask;
    import tasks.*;
    import GUI.ScriptGUI;
    
    import java.awt.*;
    import java.lang.reflect.InvocationTargetException;
    
    import static GUI.ScriptGUI.*;
    
    
    @ScriptManifest(author = "DB", name = "Fish Cook", version = 0.1, description = "Fish Cook", category = Category.FISHING)
    
    public class FishCook extends TaskScript {
    
       public static String status;
       public static boolean userInputGUI = false;
    
       @Override
       public void onStart() {
          status = "Starting script";
          SkillTracker.start(Skill.FISHING);
    
          /*addNodes(new FishingTask(), new ChoppingTask(), new CookingTask(), new DropTask());*/
          try {
             main();
          } catch (InterruptedException e) {
             e.printStackTrace();
          } catch (InvocationTargetException e) {
             e.printStackTrace();
          }
       }

    GUI Script - The IntelliJ suggestion was to add throw InterruptedException, InvocationTargetException parts.

    Spoiler
    package GUI;
    
    import javax.swing.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.reflect.InvocationTargetException;
    
    public class ScriptGUI extends JFrame {
    
        private JPanel mainPanel;
        private JComboBox fishingTypeComboBox;
        private JButton playButton;
        private JComboBox locationComboBox;
        private JCheckBox powerFishing;
    
        public ScriptGUI() {
            setContentPane(mainPanel);
            setSize(450,300);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
            setVisible(true);
    
    
            playButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                }
            });
        }
    
        public static void main() throws InterruptedException, InvocationTargetException {
            SwingUtilities.invokeAndWait(()-> {ScriptGUI myFrame = new ScriptGUI();}
            );

    Hope this helps someone!

    Link to comment
    Share on other sites

    Change that to SwingUtilities#invokeLater and wrap your GUI creation in a Runnable. Also try moving the contents of main to onStart.

    Edit: oh lol you fixed it already

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.