Hello guys!
I have a question, I want to change the color of a button on a JFrame when the player clicks on it (I already defined the location in the mousePressed() and mouseReleased() Method, here the code.
Here my render() Method:
And here my mouse Events:
I don't know how to change the color of the "Upgrade" Button now.
Thanks for help! Bye!
I have a question, I want to change the color of a button on a JFrame when the player clicks on it (I already defined the location in the mousePressed() and mouseReleased() Method, here the code.
Here my render() Method:
Java:
public void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
for (int i = 0; i < pixels.length; i++) {
pixels[i] = 0xff00ff;
}
screen.clear(0);
screen.render(0);
Graphics g = bs.getDrawGraphics();
g.create();
g.drawImage(image, 0, 0, width, height, null);
// MAIN BUTTON
g.setColor(new Color(cwhite));
g.fillRect(300, 200, rectWidth, rectHeight);
g.setColor(new Color(cblack));
g.setFont(new Font("Arial", 0, 14));
g.drawString("Click Me!", 320, 250);
// UPGRADE BUTTON
g.setColor(new Color(cwhite));
g.fillRect(610, 50, 150, 50);
g.setColor(new Color(cblack));
g.setFont(new Font("Arial", 0, 14));
g.setColor(new Color(0));
g.drawString("Upgrade your Yee!", 625, 80);
// DOUBLECOIN BUTTON
g.setColor(new Color(cwhite));
g.fillRect(50, 100, 125, 50);
g.setColor(new Color(cblack));
g.setFont(new Font("Arial", 0, 14));
g.drawString("Double your Coins!", 50, 125);
g.drawString(String.valueOf(rate), 50, 150);
// COINS
g.setFont(new Font("Arial", 0, 25));
g.setColor(new Color(cwhite));
g.drawString(String.valueOf(counter), 50, 50);
// LINE
g.drawLine(575, 0, 575, 600);
g.dispose();
bs.show();
}
And here my mouse Events:
Java:
@Override
public void mousePressed(MouseEvent e) {
if ((mousex > 610 && mousex <= 760) && (mousey >= 50 && mousey <= 100)) {
}
}
@Override
public void mouseReleased(MouseEvent e) {
if ((mousex > 610 && mousex <= 760) && (mousey >= 50 && mousey <= 100)) {
}
}
I don't know how to change the color of the "Upgrade" Button now.
Thanks for help! Bye!