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
  • Implementing netbeans swing gui builder code into dreambot script


    randalthor

    Recommended Posts

    Thanks for all your help. I now have a working script with a gui. The only thing I may change later is upgrading the paint.Summary of lessons learned for others reading this post trying to learn how to use netbeans swing gui builder to build GUIs.

     

     

    1a. First use netBeans to create a gui that looks like what you want in the design tab. Its pretty much click and drag with little coding required

     

    a. changes to the gui

    1. move the try statement and exceptions under main in the source code to the constructor

    2. initialize a private "scriptNameHere" ctx in the GUI

    3. add "scriptNameHere script" as a parameter in the constructor"

    4. add ctx = script to the constructor

    5. search for setDefaultCloseOperation and change the enum to DISPOSE_ON_CLOSE from EXIT_ON_CLOSE

    6. add <String> or <Integer> to the combo boxes code to remove the "reference to generic type should be parameterized" error

    7. use ctx. and the setter methods to change your fields. these method calls should be in the "startButtonActionPerformed" method

    8. add this.setVisible(false) to start button action to close the gui when start is pressed

     

    b. changes to main script

    1. add private "guiNameHere" gui; field

    2. add gui = new "guiNameHere"(this)  to onStart Method//this is passing in the current main script class as a parameter

    3. add gui.setVisible(true) to onStart method

    4. add setting methods for your private fields. Ex:

     

     

    public void setStartScript(boolean x) {
    startScript = x;
    }
        public void lootDistance(Integer x) {
        if(x != null)
        lootDistance = x;
        }
        
        public void foodType(String x) {
        if(x != null)
        food = x;
        }
        
       public void foodAmount(Integer x) {
      if(x != null)
      foodWithdrawConstant = x;
        }
        
        public void foodBank(Boolean x) {
        if(x != null)
        lowLevel = x;
        }
        public void lootGeneral(Boolean x) {
        if(x != null)
        wantToLoot = x;
        }
        public void lootBones(Boolean x) {
        if(x != null)
        lootBones = x;
        }
        public void ranging(Boolean x) {
        if(x != null)
        ranging = x;
        }
        public void arrowAmount(Integer x) {
        if(x != null)
        arrowAmount = x;
        }
        public void arrowType(String x) {
        if(x != null)
        arrowType = x;
        }

    Link to comment
    Share on other sites

     

    Thanks for all your help. I now have a working script with a gui. The only thing I may change later is upgrading the paint.Summary of lessons learned for others reading this post trying to learn how to use netbeans swing gui builder to build GUIs.

     

     

    1a. First use netBeans to create a gui that looks like what you want in the design tab. Its pretty much click and drag with little coding required

     

    a. changes to the gui

    1. move the try statement and exceptions under main in the source code to the constructor

    2. initialize a private "scriptNameHere" ctx in the GUI

    3. add "scriptNameHere script" as a parameter in the constructor"

    4. add ctx = script to the constructor

    5. search for setDefaultCloseOperation and change the enum to DISPOSE_ON_CLOSE from EXIT_ON_CLOSE

    6. add <String> or <Integer> to the combo boxes code to remove the "reference to generic type should be parameterized" error

    7. use ctx. and the setter methods to change your fields. these method calls should be in the "startButtonActionPerformed" method

    8. add this.setVisible(false) to start button action to close the gui when start is pressed

     

    b. changes to main script

    1. add private "guiNameHere" gui; field

    2. add gui = new "guiNameHere"(this)  to onStart Method//this is passing in the current main script class as a parameter

    3. add gui.setVisible(true) to onStart method

    4. add setting methods for your private fields. Ex:

     

     

    public void setStartScript(boolean x) {
    startScript = x;
    }
        public void lootDistance(Integer x) {
        if(x != null)
        lootDistance = x;
        }
        
        public void foodType(String x) {
        if(x != null)
        food = x;
        }
        
       public void foodAmount(Integer x) {
      if(x != null)
      foodWithdrawConstant = x;
        }
        
        public void foodBank(Boolean x) {
        if(x != null)
        lowLevel = x;
        }
        public void lootGeneral(Boolean x) {
        if(x != null)
        wantToLoot = x;
        }
        public void lootBones(Boolean x) {
        if(x != null)
        lootBones = x;
        }
        public void ranging(Boolean x) {
        if(x != null)
        ranging = x;
        }
        public void arrowAmount(Integer x) {
        if(x != null)
        arrowAmount = x;
        }
        public void arrowType(String x) {
        if(x != null)
        arrowType = x;
        }

     

    Just fyi, an integer should be passed as "int x" not "Integer x", also the "int x" will NEVER be null, so there's no need for a null check: "if(x != null)"

    Link to comment
    Share on other sites

    I saw that before but wasn't sure that a basic type couldn't be null. The parameter in those setters come from the GUI class which takes them from the combo boxes, check boxes, and text fields. I wanted to do something in case the comboBox of Integers somehow returned null when I used the method comboBox.getSelectedItem()

     

    ctx.foodAmount(new Integer((int)numFoodWithdrawn.getSelectedItem()));

     

     numFoodWithdrawn.setModel(new javax.swing.DefaultComboBoxModel<Integer>(new Integer[] { 0,1,2,3,4,5,6,7,8,9,10,15,20,25,26,27,28 }));
    Link to comment
    Share on other sites

    • 3 months later...

    I saw that before but wasn't sure that a basic type couldn't be null. The parameter in those setters come from the GUI class which takes them from the combo boxes, check boxes, and text fields. I wanted to do something in case the comboBox of Integers somehow returned null when I used the method comboBox.getSelectedItem()

     

    ctx.foodAmount(new Integer((int)numFoodWithdrawn.getSelectedItem()));

     

     numFoodWithdrawn.setModel(new javax.swing.DefaultComboBoxModel(new Integer[] { 0,1,2,3,4,5,6,7,8,9,10,15,20,25,26,27,28 }));

    "Integer x" could be null. Integer (along with Boolean, Double, ect...) values are all objects, which serves the purpose of "wrapping" a primitive value. These wrappers are reference types, thus variables of that type can reference null.

     

    It's important to know this especially when it comes to comparing them. You usually compare primitive values using ==, but for reference types it's a reference comparison, not a value comparison:

    Integer first = 1000;
    Integer second = 1000;
    System.out.println(first == second);

    prints false. The act of wrapping a primitive value in an object is called "boxing", and it may happen automatically. Boxing could drag down performance, depending on how often it's used.

    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.