The JButton (created before as a static private variable) doesn’t appear on the screen
What is hilarious is that after I do some changes to the code (even that don’t anyhow change the logic), for example change some lines in places, it does always appear on the first run after and then doesn’t show up again until the next such change
super.paintComponent(g);
if(inGame){
g.drawImage(apple,appleX,appleY,this);
g.drawString(String.valueOf("count:" + count), 10, 10);
g.drawString(String.valueOf("max:" + player.max), 90, 10);
if (right == true){
g.drawImage(snakeHeadRight, x[0], y[0], this);
}
else if(left == true){
g.drawImage(snakeHeadLeft, x[0], y[0], this);
}
else if(down == true){
g.drawImage(snakeHeadDown, x[0], y[0], this);
}
else if(up == true){
g.drawImage(snakeHeadUp, x[0], y[0], this);
}
for (int i = 1; i < sizeOfSnake; i++) {
g.drawImage(snake,x[i],y[i],this);
}
} else if (inGame == false){
String str = "START THE GAME";
g.setColor (Color.white);
g.drawString (str, 160,50);
Button button = new Button ("Play");
button.setVisible (true);
button.setLocation (160, 160);
button.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
inGame = true;
button.setVisible (false);
}
});
this.add(button);
}
}
I’m really upset cause I’ve been trying to solve this problem for over than 3 weeks now and just nothing comes to my head