Best way to do Buttons?

Hey all, I am working on a simple game just for fun and practice. I already have a way to make “buttons” in-game but I was wondering if there was a better way of doing it. Currently to do buttons I draw text to the game, make a rectangle that is the size of the text, then I make a class that extends MouseAdapter and add it to my JPanel using addMouseListener(). In the class that extends MouseAdapter I have a mousePressed() method that checks if the click is inside the button’s rectangle and acts accordingly. Is there a better/easier/simpler way to do this? Thanks in advance for any help :slight_smile:

You could create like a ButtonGroup class that implements MouseListener and add objects of type Button to it. Then when you click or hover you can run a for loop to see which button was clicked/hover and call a method in that Button.

Is this for use in conjunction with active rendering?

You can use this with active rendering if you would like. You can also call repaint() every time the mouse moves for efficiency.

Thanks that helped :P.

Glad to help! :slight_smile: