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
  • Adding swing components to the client


    Thaumaturge

    Recommended Posts

    Constantly re-compiling to tune a few variables in my code started getting annoying, so I wanted to make a control panel. Adding clickable buttons seemed to be the first step, and at first, I just painted rectangular regions on the canvas and had my script implement mouseListener so I could click on them. But having all the dummy methods bugged me, so I made a mouse adapter and tried installing it via

    getClient().getInstance().addEventListener(EventListener);
    

    However, the Listener only worked when mouse control was enabled. What I really wanted was a way to add JButtons to the client, that could be clicked whenever.

    Playing with the code posted by Hashtag (teach me to mention properly pls), here

    private void minimize() {
         ((JFrame) getClient().getInstance().getCanvas().getParent().getParent().getParent().getParent().getParent().getParent().getParent()).setState(Frame.ICONIFIED);
    }
    

    I found that by going up 5 parents, clickable JButtons could be added to the client frame. This is the code I use for a gui button:

    // The container we want is 5 parents up. Use absolute positioning
    Container container = getClient().getInstance().getCanvas().getParent().getParent()
    .getParent().getParent().getParent();
    
    // Remove the buttons that are already there, so buttons don't build up. We can't use the
    // buttons that are there already because they don't reference this script
    for (Component c : container.getComponents())
        if (c instanceof JButton)
            container.remove(c);
    // Toggles gui visibility
    JButton guiButton = new JButton("Gui");
    guiButton.addActionListener(e -> gui.setVisible(!gui.isVisible()));
    guiButton.setBounds(480, 25, 100, 40);
    container.add(guiButton);
    
    

    There are some problems with this approach, mainly that the button is Client specific, not tab specific, so the button only works on 1 script per client. If someone finds a way to make it tab specific and shares it here, that'd be great. Also, adding the buttons to any other parent component didn't seem to work, as their visibility was blocked by the game screen. Still not sure about the exact way the components are layered, more info on that would be appreciated too.

    Results are attached.

    post-100397-0-20580600-1503877207_thumb.jpg

    post-100397-0-23891600-1503877209_thumb.jpg

    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.