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
  • GUI problem on my script


    RetroBot

    Recommended Posts

    The GUI works fine when I first run the script, but when I stop the script and start it back up again the GUI pops up for a second then closes immediately. How can I solve this problem? Any help is much appreciated.

    @Override
        public void onStart() {
            startTime = System.currentTimeMillis();
    
            GUI GUI = new GUI();
    
            Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
            int screenW = (screensize.width) / 2;
            int screenH = (screensize.height) / 2;
    
            GUI.setVisible(true);
    
            GUI.setLocation((screenW / 2), (screenH / 2));
    
            while (!GUI_COMPLETE) {
                sleep(500);
            }
    
            GUI.setVisible(false);
    
            log("Script has started!");
        }
    
    Link to comment
    Share on other sites

    Try doing something about that while loop. On exit set gui_complete true or break the loop is gui is not visible

     

    I set gui_complete to true when I press the start button (forgot to post that part)

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) throws IOException {
            Main.GUI_COMPLETE = true;
            playerSettings = playerCheck.isSelected();
            npcSettings = npcCheck.isSelected();
            lootSettings = lootCheck.isSelected();
            destinationCombobox = destinationCombo.getSelectedItem().toString();
        }
    
    Link to comment
    Share on other sites

     

    I set gui_complete to true when I press the start button (forgot to post that part)

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) throws IOException {
            Main.GUI_COMPLETE = true;
            playerSettings = playerCheck.isSelected();
            npcSettings = npcCheck.isSelected();
            lootSettings = lootCheck.isSelected();
            destinationCombobox = destinationCombo.getSelectedItem().toString();
        }
    

    Based off this code, can't tell. But if you're trying to set the gui in the middle of the screen do this

     

    gui.setLocationRelativeTo(null);

     

     

    Also

     

    -Make your GUI a field, not a local variable in the onStart

    -Dont make the GUI variable name the exact same as its type

    --GUI GUI = new GUI() <--bad

    --Gui gui = new GUI() <--good

    Link to comment
    Share on other sites

     

    The GUI works fine when I first run the script, but when I stop the script and start it back up again the GUI pops up for a second then closes immediately. How can I solve this problem? Any help is much appreciated.

    @Override
        public void onStart() {
            startTime = System.currentTimeMillis();
    
            GUI GUI = new GUI();
    
            Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
            int screenW = (screensize.width) / 2;
            int screenH = (screensize.height) / 2;
    
            GUI.setVisible(true);
    
            GUI.setLocation((screenW / 2), (screenH / 2));
    
            while (!GUI_COMPLETE) {
                sleep(500);
            }
    
            GUI.setVisible(false);
    
            log("Script has started!");
        }
    

    Instead of

     Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
            int screenW = (screensize.width) / 2;
            int screenH = (screensize.height) / 2;
    
            GUI.setVisible(true);
    
            GUI.setLocation((screenW / 2), (screenH / 2));
    

    just do

    GUI.setLocationRelativeTo(null);

    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.