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
  • JcomboBox actionlistener and string selection


    HTM

    Recommended Posts

    Basically i am trying to make my script select one of the drop downs from the combobox and initiate which path to run from there however i can not seem to iron this out. 2hours later and i decided to concede and ask for advice. one of 2 things happens. either the code will not select anything even the choice i chose from the dropdown or the code will decide to select all of the choice and make everything true which causes my script to crash. any idea how to fix this combobox issue?

     

    public static void createFishingGUI(Component client, Main context) {
        log("Fishing GUI started");
        context.botState = BotState.getState(context);
        SkillTracker.start(FISHING);
        JFrame frame = new JFrame();
        frame.setTitle("AioFisher");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLocationRelativeTo(client);
        frame.setPreferredSize(new Dimension(400, 100));
        frame.getContentPane().setLayout(new BorderLayout());
        frame.setVisible(true);
        frame.pack();
        JPanel settingPanel = new JPanel();
        settingPanel.setLayout(new GridLayout(0, 2));
        JLabel label = new JLabel();
        label.setText("Fishing Location:");
        settingPanel.add(label);
        JComboBox<String> LocationComboBox1 = new JComboBox<>(new String[]{
                "Lumbridge-Shrimp", "Draynor-Shrimp", "Barbarian Village-FlyFishing", "Barbarian Outpost-BarbFishing", "Shilo Village-FlyFishing"});
        settingPanel.add(LocationComboBox1);
        frame.getContentPane().add(settingPanel, BorderLayout.CENTER);
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout());
        JButton button = new JButton();
        button.setText("Start Script");
        button.addActionListener(e -> {
            FishingSkill.fishingLocation = LocationComboBox1.getSelectedItem().toString();
            LocationComboBox1.addActionListener(e1 -> {
                        if (LocationComboBox1.getSelectedItem().equals("Lumbridge-Shrimp")) {
                            FishingSkill.setisLumbridgeShrimp(true);
                            log("Lumbridge selected");
                        }
                        if (LocationComboBox1.getSelectedItem().equals("Draynor-Shrimp")) ;
                        {
                            FishingSkill.setisDraynorShrimp(true);
                            log("Draynor Selected");
                        }
                        if (LocationComboBox1.getSelectedItem().equals("Barbarian Village-FlyFishing")) ;
                        {
                            FishingSkill.setisBarbVillFishing(true);
                            log("BB Vill Selected");
                        }
                        if (LocationComboBox1.getSelectedItem().equals("Shilo Village-FlyFishing")) ;
                        {
                            FishingSkill.setisShiloVillFishing(true);
                            log("Shilo Vill Selected");
                        }
                    });
    
            context.botState.setRunning(true);
            FishingSkill.setisFishing(true);
            timeRan = new Timer();
            frame.dispose();
    
    
    
    
        });
        buttonPanel.add(button);
        frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    }

     

     

     

    @Override
    public int onLoop() {
        if (botState.getRunning()) {
            if(FishingSkill.getisFishing()) {
                FishingSkill.TrainingFishing();
            }
        }

     

     

     

    public class FishingSkill extends Main {
    
        public static boolean startFishing = false;
        public static boolean getStartFishing() {
            return startFishing;
        }
        public static void setStartFishing(boolean val) {
            startFishing = val;
        }
    
        public static String fishingLocation;
        public static boolean isFishing = false;
        public static boolean getisFishing() {
            return isFishing;
        }
        public static void setisFishing(boolean val) {
            isFishing = val;
        }
    
        public static boolean isLumbridgeShrimp = false;
        public static boolean getLumbridgeShrimp() {
            return isLumbridgeShrimp;
        }
        public static void setisLumbridgeShrimp(boolean val) {
            isLumbridgeShrimp = val;
        }
    
        public static boolean isDraynorShrimp = false;
        public static boolean getDraynorShrimp() {
            return isDraynorShrimp;
        }
        public static void setisDraynorShrimp(boolean val) {
            isDraynorShrimp = val;
        }
    
        public static boolean isBarbVillFishing = false;
        public static boolean getBarbVillFishing() {
            return isBarbVillFishing;
        }
        public static void setisBarbVillFishing(boolean val) {
            isBarbVillFishing = val;
        }
    
        public static boolean isShiloVillFishing = false;
        public static boolean getShiloVillFishing() {
            return isShiloVillFishing;
        }
        public static void setisShiloVillFishing(boolean val) {
            isShiloVillFishing = val;
        }
    
    
        public static void TrainingFishing() {
            if(getLumbridgeShrimp()) {
                log("lumby fishing");
                LumbyShrimpFishing();
            }
             else if (getDraynorShrimp()) {
                log("Draynor Shrimp fishing");
                DraynorShrimpFishing();
            }
                else if (getBarbVillFishing()) {
                    log("BarbVill FlyFishing");
                    BarbVillFishing();
            }
                     else if (getShiloVillFishing()) {
                         log("Shilo Village Fishing");
    
            }
            else{
                log("no choices selected, retry");
            }
        }
    Link to comment
    Share on other sites

    figured it out incase anyone is curious, i needed to remove my breaks ";" at the end of my if's

     

    label.setText("Fishing Location:");
    settingPanel.add(label);
    JComboBox<String> LocationComboBox1 = new JComboBox<>(new String[]{
            "Lumbridge Shrimp", "Draynor Shrimp", "Barbarian Village FlyFishing", "Barbarian Outpost BarbFishing", "Shilo Village FlyFishing"});
    settingPanel.add(LocationComboBox1);
    LocationComboBox1.addActionListener(e -> {
                FishingSkill.fishingLocation = LocationComboBox1.getSelectedItem().toString();
                if (LocationComboBox1.getSelectedItem().equals("Lumbridge Shrimp")){
                    FishingSkill.setisLumbridgeShrimp(true);
                    log("Lumbridge selected");
                }
                if (LocationComboBox1.getSelectedItem().equals("Draynor Shrimp")){
                    FishingSkill.setisDraynorShrimp(true);
                    log("Draynor Selected");
                }
                if (LocationComboBox1.getSelectedItem().equals("Barbarian Village FlyFishing")){
                    FishingSkill.setisBarbVillFishing(true);
                    log("BB Vill Selected");
                }
    
                if (LocationComboBox1.getSelectedItem().equals("Shilo Village FlyFishing")){
                    FishingSkill.setisShiloVillFishing(true);
                    log("Shilo Vill Selected");
                }
            });
    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.