Own buttons with events - is this ok?

I have created some simple buttons for an Android game and wanted to run the idea/logic by the forum to get feedback. I have classes which have vars like:

Button Class
float x, y, width, height;
Rectanlge hitbox;
String event;

Touch Class
float touch_x, touch+y;
Rectanlge hitbox;
boolean handled;

Concept
A simple screen might have 4 buttons that are put into an array, when the screen is pressed the x and y are captured and handled set to false, I then loop the button array checking for intersects and if true set menu_action to the button.event and set handled back to true.

I would handle this event and set some other boolean or string to false or “” so I know that event has been handled. When handled is true there is no need to loop the button array.

I could use scene2D but it felt overkill for such a simple task and I should imagine it deals with inputs in some similar way, checking each button that is listening?

This does work in my app I would just like some pro’s or con’s of doing this, is this bad practice?

Once you learn scene2d it is easy to use. Do not reinvent the wheel if you do not have to.

The x, y, width, and height variables are redundant if you store a rectangle.
All you need is:

rect.contains(x, y);
//or
rect.contains(Point p);

Touch could either have an x and y or extend Point, adding the ‘handled’ field. No reason for a rectangle or intersects().

You are correct in using a ‘handled’ flag, it is used to prevent gui elements from handling events when they are underneath another element. This only works if the elements are collision-checked in order.

If that is guaranteed to never be a scenario, it is ‘overkill.’

Also, don’t use “” strings (or null objects) to represent a boolean state. Just use a boolean.

Past this much functionality, you might as well use scene2d, or utilize Swing if applicable, i.e. using JComponent/JPanel and MouseEvent/MouseListener.

Thanks for the tips, the rectangle on they touched area is pointless so can remove that. I generally use booleans but will make a mental note not to dp otherwise.

Scene2D does look easy I was just wondering if its needed for such simple menus. I will give it a go at some point.