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
  • Try asking for help in the chatbox
  • Gui won't show on start


    deathizpro
     Share

    Recommended Posts

    In the process of transferring my scripts over from another client. Can't seem to make the GUI pop up. The other client had a client-embedded interface and supported JFX so their gui system was a lot different. Followed computors guide using JForm Designer to make writing out the swing elements a lot quicker and get the GUI to show. Comparing our codes, theres not really much difference and his GUI pops up fine.

     

    In my onStart() method I initialize my Gui variable and set it to visible

    gui = new BotGui(this);
    gui.setVisible(true);
    

    And the gui never pops up on start. Without the gui, everything runs fine. 3 of my variables are required in the bot logic to give the user choices, but if permanently set them the bot will run fine.

     

    Heres the GUI code:

    public class BotGui extends JFrame {
    
    
    
    private Bot script;
    
    public BotGui(Bot main) {
    
    this.script = main;
    
    initComponents();
    
    }
    
    
    
    private void getFoodChoice(ActionEvent e) {
    
    script.setFood(foodChoice.getSelectedItem().toString());
    
    }
    
    
    
    private void getWithdrawAmt(ActionEvent e) {
    
    script.foodAmt = Integer.parseInt(foodAmt.getSelectedItem().toString());
    
    }
    
    
    
    private void getHealChoice(ActionEvent e) {
    
    if (healChoice.isSelected()) {
    
    script.eatAtBank = true;
    
    } else {
    
    script.eatAtBank = false;
    
    }
    
    }
    
    
    
    private void getStartButtonAction(ActionEvent e) {
    
    script.waitForGui = false;
    
    this.setVisible(false);
    
    }
    
    
    
    private void initComponents() {
    
    foodChoice = new JComboBox<>();
    
    label1 = new JLabel();
    
    label2 = new JLabel();
    
    foodAmt = new JComboBox<>();
    
    healChoice = new JCheckBox();
    
    startButton = new JButton();
    
    
    
    //======== this ========
    
    setTitle("Bot");
    
    Container contentPane = getContentPane();
    
    contentPane.setLayout(null);
    
    
    
    //---- foodChoice ----
    
    foodChoice.setFont(new Font("Century Gothic", Font.PLAIN, 12));
    
    foodChoice.setModel(new DefaultComboBoxModel<>(new String[] {
    
    "Trout",
    
    "Shark"
    
    }));
    
    foodChoice.addActionListener(e -> getFoodChoice(e));
    
    contentPane.add(foodChoice);
    
    foodChoice.setBounds(125, 25, 165, 35);
    
    
    
    //---- label1 ----
    
    label1.setText("Choose a food:");
    
    label1.setFont(new Font("Century Gothic", Font.PLAIN, 12));
    
    contentPane.add(label1);
    
    label1.setBounds(15, 25, 100, 30);
    
    
    
    //---- label2 ----
    
    label2.setText("Withdraw Amt:");
    
    label2.setFont(new Font("Century Gothic", label2.getFont().getStyle(), label2.getFont().getSize() - 1));
    
    contentPane.add(label2);
    
    label2.setBounds(15, 80, 85, 45);
    
    
    
    //---- foodAmt ----
    
    foodAmt.setFont(new Font("Century Gothic", Font.PLAIN, 12));
    
    foodAmt.setModel(new DefaultComboBoxModel<>(new String[] {
    
    "5",
    
    "6",
    
    "7",
    
    }));
    
    foodAmt.setSelectedIndex(2);
    
    foodAmt.addActionListener(e -> getWithdrawAmt(e));
    
    contentPane.add(foodAmt);
    
    foodAmt.setBounds(125, 85, 95, 36);
    
    
    
    //---- healChoice ----
    
    healChoice.setText("Heal before going again?");
    
    healChoice.setFont(new Font("Century Gothic", Font.PLAIN, 12));
    
    healChoice.addActionListener(e -> getHealChoice(e));
    
    contentPane.add(healChoice);
    
    healChoice.setBounds(new Rectangle(new Point(95, 140), healChoice.getPreferredSize()));
    
    
    
    //---- startButton ----
    
    startButton.setText("Start");
    
    startButton.setFont(new Font("Century Gothic", Font.PLAIN, 12));
    
    startButton.addActionListener(e -> getStartButtonAction(e));
    
    contentPane.add(startButton);
    
    startButton.setBounds(new Rectangle(new Point(125, 180), startButton.getPreferredSize()));
    
    
    
    contentPane.setPreferredSize(new Dimension(325, 240));
    
    pack();
    
    setLocationRelativeTo(getOwner());
    
    }
    
    
    
    private JComboBox<String> foodChoice;
    
    private JLabel label1;
    
    private JLabel label2;
    
    private JComboBox<String> foodAmt;
    
    private JCheckBox healChoice;
    
    private JButton startButton;
    
    }
    
    Link to comment
    Share on other sites

    you really think hes gonna be able to do that lol

     

    Open dreambot is command line and check to see if any errors

    He should be able to, I think. It's not that hard

    Link to comment
    Share on other sites

    Did that.
     
    First time I put a breakpoint right on the onStart() method since I call both of my variables at the very top of onStart(); Bot froze upon start. Added a log line right above the initialization and setting visible of the JFrame in the onStart method but nothing happens. The debug connects to the local host fine but I never get the option to step into/over lines of code in IntelliJ.
     
    Also just using the logs on the command prompt, I get one error upon initially running, and stopping the script when the GUI doesn't show up. Apart from that, what I put specifically in the script to say the GUI is taking too long is all I get (put a timeout at the top of my onLoop() to wait 60 seconds for user input, or otherwise logout and stop the script).
     
    Debugger console only says:

    Connected to the target VM, address: 'localhost:12345', transport: 'socket'

    with no options to step through/into/over;
    Stopping it or closing the cmd prompt says:

    Disconnected from the target VM, address: 'localhost:12345', transport: 'socket'
    

    The log error (only happens when I first run and stop the script. I can run/stop it multiple times after and not get this error?):

    log4j:ERROR No output stream or file set for the appender named [LocalFile]
    
    Edited by deathizpro
    Link to comment
    Share on other sites

    I'm not sure. Make sure all your imports are awt and not javafx. If you put a log before and after creating and setting the gui visible, are they printed out?

    Link to comment
    Share on other sites

    All of them are .awt & swing. I can't find the problem haha.

     

    Also updated with a side note:

    I have the script set so that my onExit() prints out progress to the log and stops the script, but I also have cases in my loop where if 'this' = false/true/etc, logout and stop (e.g. if out of food in bank). The script is set so that pressing the start button on the GUI sets a boolean to true and allows for the loop to run, and otherwise not pressing it stalls the loop until start is pressed or a timer is hit. If I press nothing when I run my script, the bot will wait like it should; but when I press the stop button manually after the GUI doesn't pop up, the bot will bypass that case and begin the loop as if the start button has been pressed? So it'll begin banking or walking and won't stop until it has hit it's logout/stop cases in the loop. Should that be happening?

    Link to comment
    Share on other sites

    I usually use this, which works:

     

    GUI class:

    public class WaiterGUI extends JFrame{
    //fields, variables
    	
    	public static void main(String[] args) {
    		WaiterGUI gui = new WaiterGUI();
    		gui.setVisible(true);
    	}
    	
    	public WaiterGUI() {
    //code for the GUI
    }
    

    Using a main method in the GUI, you can easily run and test your event handlers in your IDE (eclipse = F11 key). You don't need the main method in the gui class, it's just for testing.

     

     

    Main class:

    	@Override
    	public void onStart() {	
    		WaiterGUI gui = new WaiterGUI();
    		gui.setVisible(true);
    		gui.setLocationRelativeTo(null);
        	
    		while(gui.isVisible()){
        		sleep(20,50);
        	}
    }
    
    

    Maybe the problem comes with you initialising "this" in your GUI method?

    Edited by Cardozz
    Link to comment
    Share on other sites

    That fixed it. Turns out it wasn't the initializing this, the only line I had to add was the

     

    gui.setLocationRelativeTo(null);

     

    :lol: Back in business.

    Edited by deathizpro
    Link to comment
    Share on other sites

    That fixed it. Turns out it wasn't the initializing this, the only line I had to add was the

    gui.setLocationRelativeTo(null);

    :lol: Back in business.

     

    All that line does is just set the location relative to a component. If it's set to null, it will center the frame in your screen. Doesn't really do much with the GUI itself. No idea why it works with that line lol.

     

    Anyway, glad i could help :)

    Link to comment
    Share on other sites

     Share

    ×
    ×
    • 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.