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

    The title pretty much says it all. I'm trying to add a working GUI code to my dreambot script: http://pastebin.com/8txnveu4   simple copy and pasting it into the current script isn't working. I'm unfamiliar with how to combine the two. I suspect I have to do something like with using the API and accessing methods from my GUI code from the main script but I'm not sure. Both help and direction to instructional materials on how to do this would be appreciated.

     

    Link to comment
    Share on other sites

    In "Series 2" of this tutorial I show you how to do this: http://dreambot.org/forums/index.php/topic/2555-video-tutorial-series-dreambot-scripting-request-scripting-tutorials-here/

     

    Without having to watch the entire video, here's how:

     

     

    package AIOFisher.Enums;
    
    import org.dreambot.api.script.AbstractScript;
     
    /**
     *
     * @author Joshua
     */
    public class EdgeManFighterGUIUI extends javax.swing.JFrame {
    
        /**
         * Creates new form EdgeManFighterGUIUI
         */
        private AbstractScript ctx;
        public EdgeManFighterGUIUI(AbstractScript script) {
            initComponents();
            ctx = script;
    
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUIUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUIUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUIUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUIUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
        }
    
        /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            foodType = new javax.swing.JComboBox();
            jLabel5 = new javax.swing.JLabel();
            foodTypeCustom = new javax.swing.JTextField();
            useCustomFood = new javax.swing.JCheckBox();
            jLabel6 = new javax.swing.JLabel();
            foodWithdrawn = new javax.swing.JTextField();
            maxLootDistance = new javax.swing.JTextField();
            lowLevel = new javax.swing.JCheckBox();
            jLabel7 = new javax.swing.JLabel();
            looting = new javax.swing.JCheckBox();
            loootingBones = new javax.swing.JCheckBox();
            jLabel8 = new javax.swing.JLabel();
            amRanging = new javax.swing.JCheckBox();
            jLabel2 = new javax.swing.JLabel();
            arrowStack = new javax.swing.JComboBox();
            jLabel9 = new javax.swing.JLabel();
            arrowType = new javax.swing.JComboBox();
            jLabel10 = new javax.swing.JLabel();
            startButton = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    
            jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
            jLabel1.setText("Combined Variables:");
    
            jLabel3.setText("Max Loot Distance(integer):");
    
            jLabel4.setText("Food type");
    
            foodType.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Trout", "Shrimp", "Herring", "Pike", "Salmon", "Tuna", "Lobster", "Swordfish"}));
    
            jLabel5.setText("Custom food(single bite):");
    
            foodTypeCustom.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    foodTypeCustomActionPerformed(evt);
                }
            });
    
            useCustomFood.setText("toggle custom");
            useCustomFood.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    useCustomFoodActionPerformed(evt);
                }
            });
    
            jLabel6.setText("# food withdrawn(integer):");
    
            lowLevel.setText("bank when out of food");
    
            jLabel7.setText("(always banks when inventory is full)");
    
            looting.setText("loot general drops");
    
            loootingBones.setText("loot bones");
            loootingBones.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    loootingBonesActionPerformed(evt);
                }
            });
    
            jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
            jLabel8.setText("Ranged Variables:");
    
            amRanging.setText("check when ranging");
            amRanging.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    amRangingActionPerformed(evt);
                }
            });
    
            jLabel2.setText("Minimum arrow stack to loot:");
    
            arrowStack.setModel(new javax.swing.DefaultComboBoxModel(new Integer[]{3, 1, 2, 4, 5, 6, 7, 8, 9, 10}));
    
            jLabel9.setText("Arrow Type:");
    
            arrowType.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Bronze arrow", "Iron arrow", "Steel arrow", "Mithril arrow", "Adamant arrow", "Bronze bolts"}));
    
            jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
            jLabel10.setText("Rand's men fighter:");
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(looting)
                                            .addComponent(loootingBones)
                                            .addComponent(jLabel8)
                                            .addComponent(amRanging)
                                            .addComponent(jLabel1)
                                            .addComponent(jLabel10)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                    .addGap(2, 2, 2)
                                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                                    .addComponent(jLabel4)
                                                                    .addGap(2, 2, 2)
                                                                    .addComponent(foodType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                    .addComponent(jLabel5)
                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                    .addComponent(foodTypeCustom, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                    .addComponent(useCustomFood))
                                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                                    .addComponent(jLabel3)
                                                                    .addGap(18, 18, 18)
                                                                    .addComponent(maxLootDistance, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                                    .addComponent(jLabel6)
                                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                    .addComponent(foodWithdrawn, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                    .addComponent(lowLevel)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(jLabel7))
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                    .addComponent(jLabel2)
                                                    .addGap(2, 2, 2)
                                                    .addComponent(arrowStack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                    .addComponent(jLabel9)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(arrowType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addContainerGap(93, Short.MAX_VALUE))
            );
    
            jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]{foodTypeCustom, foodWithdrawn, maxLootDistance});
    
            jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]{arrowStack, arrowType, foodType});
    
            jPanel1Layout.setVerticalGroup(
                    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel10)
                                    .addGap(5, 5, 5)
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(maxLootDistance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel3))
                                    .addGap(1, 1, 1)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel4)
                                            .addComponent(jLabel5)
                                            .addComponent(foodType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(foodTypeCustom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(useCustomFood))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel6)
                                            .addComponent(foodWithdrawn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(looting)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(loootingBones)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(lowLevel)
                                            .addComponent(jLabel7))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel8)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(amRanging)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel2)
                                            .addComponent(arrowStack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel9)
                                            .addComponent(arrowType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            );
    
            startButton.setText("Start");
            startButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    startButtonActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                    .addGap(0, 0, Short.MAX_VALUE)
                                                    .addComponent(startButton)))
                                    .addContainerGap())
            );
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(startButton)
                                    .addContainerGap())
            );
    
            pack();
        }// </editor-fold>
    
        private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
    
        private void amRangingActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
    
        private void loootingBonesActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
    
        private void useCustomFoodActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
    
        private void foodTypeCustomActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        }
    
        // Variables declaration - do not modify
        private javax.swing.JCheckBox amRanging;
        private javax.swing.JComboBox arrowStack;
        private javax.swing.JComboBox arrowType;
        private javax.swing.JComboBox foodType;
        private javax.swing.JTextField foodTypeCustom;
        private javax.swing.JTextField foodWithdrawn;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel10;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JCheckBox loootingBones;
        private javax.swing.JCheckBox looting;
        private javax.swing.JCheckBox lowLevel;
        private javax.swing.JTextField maxLootDistance;
        private javax.swing.JButton startButton;
        private javax.swing.JCheckBox useCustomFood;
        // End of variables declaration
    }
    

     

     

     

    Then all you have to do is (in your main script) add a new gui class (as a global variable):

    private EdgeManFighterGUIUI gui;
    

    Then make it visible in your onStart method:

    gui = new EdgeManFighterGUIUI(this);
    
    gui.setVisible(true);
    
    Link to comment
    Share on other sites

    The title pretty much says it all. I'm trying to add a working GUI code to my dreambot script: http://pastebin.com/8txnveu4   simple copy and pasting it into the current script isn't working. I'm unfamiliar with how to combine the two. I suspect I have to do something like with using the API and accessing methods from my GUI code from the main script but I'm not sure. Both help and direction to instructional materials on how to do this would be appreciated.

    I would recommend removing this line. It will close the whole client if the user exits out of your gui. Ill take another look and see if i can find anything else

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    Its on line 54

    Link to comment
    Share on other sites

    Thanks for the help with that computer. Watching your videos made me realize my code is not that readable or efficient. Can you explain how to do a lambda expression for searching for game objects or ground items? I have a filter implementation working but would like to cut out a few lines.

     

    loot = getGroundItems().closest(new Filter<GroundItem>() {
         @Override
         public boolean match (GroundItem target) {
              return (target.getName().equals("Bones")) && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
         }
    });
     
    loot = getGroundItems().closest(p -> p.getName().equals("Bones")) && getMap().canReach(p) && getInventory().getEmptySlots() >= 1;
    the error is "p cannot be resolved to a variable" I recognize how "target" was used in the filter but am not sure how to do that in a lambda expression. I thought it was just the symbol to the left of the ->

    According to what I rad about lambda expressions:

    this

    loot = getGroundItems().closest((GroundItem p) -> p.getName().equals("Bones")) && getMap().canReach(p) && getInventory().getEmptySlots() >= 1;

    or this

    loot = getGroundItems().closest((p) -> p.getName().equals("Bones")) && getMap().canReach(p) && getInventory().getEmptySlots() >= 1;

    should both work as "loot" is already created as a null GroundItem earlier in the method.. The variables to the left of the -> do not have to be case to a Class, as the method selects the most likely object

     

    after rewriting my script to compile to jdk 1.8.60 and (java 8) and messing around a bit with the syntax I got these three different versions to compile without errors now to test if they work in action:

     

    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(new Tile(GroundItem.getX(), GroundItem.getY(), GroundItem.getZ()))) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(GroundItem)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));
    Link to comment
    Share on other sites

    Thanks for the help with that computer. Watching your videos made me realize my code is not that readable or efficient. Can you explain how to do a lambda expression for searching for game objects or ground items? I have a filter implementation working but would like to cut out a few lines.

     

    loot = getGroundItems().closest(new Filter<GroundItem>() {
         @Override
         public boolean match (GroundItem target) {
              return (target.getName().equals("Bones")) && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
         }
    });
     
    loot = getGroundItems().closest(p -> p.getName().equals("Bones")) && getMap().canReach(p) && getInventory().getEmptySlots() >= 1;
    the error is "p cannot be resolved to a variable" I recognize how "target" was used in the filter but am not sure how to do that in a lambda expression. I thought it was just the symbol to the left of the ->

    According to what I rad about lambda expressions:

    this

    loot = getGroundItems().closest((GroundItem p) -> p.getName().equals("Bones")) && getMap().canReach(p) && getInventory().getEmptySlots() >= 1;

    or this

    loot = getGroundItems().closest((p) -> p.getName().equals("Bones")) && getMap().canReach(p) && getInventory().getEmptySlots() >= 1;

    should both work as "loot" is already created as a null GroundItem earlier in the method.. The variables to the left of the -> do not have to be case to a Class, as the method selects the most likely object

    So you can't use the variable p like that sadly :(

     

    Here's how to do it:

    GroundItem loot = getGroundItems().closest(target -> (target.getName().equals("Bones")) && getMap().canReach(target) && getInventory().getEmptySlots() >= 1);
    

    You can change the keyword (variable) "target" to whatever you like however, so same example different name ("p"):

    GroundItem loot = getGroundItems().closest(p -> (p.getName().equals("Bones")) && getMap().canReach(p) && getInventory().getEmptySlots() >= 1);
    
    Link to comment
    Share on other sites

    after rewriting my script to compile to jdk 1.8.60 and (java 8) and messing around a bit with the syntax I got these three different versions to compile without errors not to test if they work in action:

     

    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(new Tile(GroundItem.getX(), GroundItem.getY(), GroundItem.getZ()))) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(GroundItem)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));

    after rewriting my script to compile to jdk 1.8.60 and (java 8) and messing around a bit with the syntax I got these three different versions to compile without errors not to test if they work in action:

     

    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(new Tile(GroundItem.getX(), GroundItem.getY(), GroundItem.getZ()))) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(GroundItem)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));
    Link to comment
    Share on other sites

    I would recommend removing this line. It will close the whole client if the user exits out of your gui. Ill take another look and see if i can find anything else

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    Its on line 54

     

    Don't remove, just change to this =]

     

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    Link to comment
    Share on other sites

     

    Don't remove, just change to this =]

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    already got it in my code :D

     

     

    after rewriting my script to compile to jdk 1.8.60 and (java 8) and messing around a bit with the syntax I got these three different versions to compile without errors not to test if they work in action:

     

    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(new Tile(GroundItem.getX(), GroundItem.getY(), GroundItem.getZ()))) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(GroundItem)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));

    after rewriting my script to compile to jdk 1.8.60 and (java 8) and messing around a bit with the syntax I got these three different versions to compile without errors not to test if they work in action:

     

    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(new Tile(GroundItem.getX(), GroundItem.getY(), GroundItem.getZ()))) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem) -> (GroundItem != null) && (GroundItem.getName().equals("Bones")) && (getMap().canReach(GroundItem)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((GroundItem p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));
     
    loot = getGroundItems().closest((p) -> (p != null) && (p.getName().equals("Bones")) && (getMap().canReach(p)) && (getInventory().getEmptySlots() >= 1));

     

    It's kinda of weird putting the "(p)" in parentheses like that. Instead just say "p". And like I said, using the lambda, you are able to change the name of the "target" to whatever you like, whether that be "GroundItem" (don't do this, instead write "groundItem") or "p"

    Link to comment
    Share on other sites

    Can you explain why you did your changes: removing main and moving the try statement to the constructor:

     

     

        //@param args the command line arguments
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
     
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new EdgeManFighterGUI().setVisible(true);
                }
            });
        }

    Also i have a couple warning saying ctx is not used and  @SuppressWarnings("unchecked") is unnecessary. Do I have to write getters like you did in your tutorial to set the fields in my main script?
    I guess i have to use ctx to set the fields around line 250 where is asks for handling code.

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
     
        private void amRangingActionPerformed(java.awt.event.ActionEvent evt) {                                          
            // TODO add your handling code here:
        }                                         
     
        private void loootingBonesActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void useCustomFoodActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void foodTypeCustomActionPerformed(java.awt.event.ActionEvent evt) {                                               
            // TODO add your handling code here:
        }                                              
     

     
    so that means adding setter methods to my main class to call from the gui class right?
     
    or is it better to add getter methods to the GUI to get the information while in the main class and set the private fields directly besides the onStart boolean?
     
    ah. so instead of AbstractScript in my constructor i need the name of my main class in the constructor if i want to implement a custom setter...
    Link to comment
    Share on other sites

     

    Can you explain why you did your changes: removing main and moving the try statement to the constructor:

     

     

        //@param args the command line arguments
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(EdgeManFighterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
     
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new EdgeManFighterGUI().setVisible(true);
                }
            });
        }

    Also i have a couple warning saying ctx is not used and  @SuppressWarnings("unchecked") is unnecessary. Do I have to write getters like you did in your tutorial to set the fields in my main script?
    I guess i have to use ctx to set the fields around line 250 where is asks for handling code.

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
     
        private void amRangingActionPerformed(java.awt.event.ActionEvent evt) {                                          
            // TODO add your handling code here:
        }                                         
     
        private void loootingBonesActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void useCustomFoodActionPerformed(java.awt.event.ActionEvent evt) {                                              
            // TODO add your handling code here:
        }                                             
     
        private void foodTypeCustomActionPerformed(java.awt.event.ActionEvent evt) {                                               
            // TODO add your handling code here:
        }                                              
     

     
    so that means adding setter methods to my main class to call from the gui class right?
     
    or is it better to add getter methods to the GUI to get the information while in the main class and set the private fields directly besides the onStart boolean?

     

    The constructor will initiate when you create the class, so it'll be implemented no matter what. I removed your main because you don't need it/it won't work with it. Your "executable" code is mainScript which extends AbstractScript. You will never be running the GUI from the system, only through dreambot. I add getters/setters because it's good practice to create private variables, then get/set them with functions. Is it required? No.

     

    Yes you need to use ctx ("context" from your AbstractScript class) in those action events if you want to do things with them.

     

    To check if a checkbox is checked or not you would do: checkbox.isSelected(); Which returns a boolean (true if selected).

     

     

    So:

    private JCheckBox lootBones;
    
    public boolean getLootBones(){
        return lootBones.isSelected();
    }
    
    

    Then in your main class you'd do something like...

    if(gui.getLootBones()){
        //loot the nearest bones to you
    }
    
    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.