Thaumaturge 4 Share Posted August 27, 2017 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. Link to comment Share on other sites More sharing options...
Scorpius 144 Share Posted August 28, 2017 Holy fuck nice! Link to comment Share on other sites More sharing options...
Thaumaturge 4 Author Share Posted August 28, 2017 Holy fuck nice! Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.