I’m assuming we’re talking about your input handler. The “static” comment was referring to this part of your code:
if (butt.contains(Button.mse))
“mse” would have to be a static member of the Button class for the above to make sense. Ideally, your Button class would look something like:
public class Button extends Rectangle {
public static final long serialVersionUID = 1L;
BufferedImage button;
public Button(String msg, int x, int y) {
setBounds(x, y, Art.b1.getWidth(), Art.b1.getHeight());
System.out.println(getBounds());
button = Art.b1;
String mval = msg;
}
public render(Graphics g) {
g.drawImage(button, x, y, null);
Fonts.drawString(mval, x + 20, y + 20);
}
public boolean tick(Point mse) {
if (contains(mse)) {
// Change to the hovered
button = Art.b2;
System.out.println("Woohoo!");
return true;
}
button = Art.b1;
return false;
}
}
Then your input handlers mouse move event would look something like this:
public void mouseMoved(MouseEvent e) {
if (game.state == 1) {
// Get a reference to your button here...we'll call it theButton in this case.
theButton.tick(e.getPoint());
} else if (game.state == 0) {
// Do something else...
}
}
The boolean on the tick event can be omitted if you’re only using one button. If you’re using more, then it becomes useful when iterating over multiple button objects (as in Slyth2727’s scenario) to determine if the event has been processed by a particular button thus ending the iteration loop.
BurntPizza’s recommendations are also solid and pretty much how my GUI controls are implemented as well. It adds a bit of complexity in the short term, but makes things far easier in the long term. Delving into the source for Java’s Component class may also provide some enlightenment/ideas for how to implement your controls.