0

Everything here works perfectly except for the fact that buttons 1,2 and 3 do not change color when needed, I think this has something to do with(try-catch)? IDK I'm pretty new at coding so I can't tell, plz help!

if(b1 ==("X") && b2 == ("X") && b3 ==("X"))
{
    JOptionPane.showMessageDialog(this, "Player X Wins!!");
    xCount++;
    gameScore();
    txtbtn1.setBackground(Color.YELLOW);
    txtbtn2.setBackground(Color.yellow);
    txtbtn3.setBackground(Color.yellow);
    try{
        Thread.sleep(1000);
    } catch(InterruptedException ex){
        Thread.currentThread().interrupt();
    }
    ResetGame();
}
camickr
  • 321,443
  • 19
  • 166
  • 288
  • 2
    When is this block executed? Im 99.9% sure `Thread.sleep(1000)` is the bad boy here. What are you trying to achieve? Are you blocking the Main-Thread? Does [this](https://stackoverflow.com/questions/14106953/swing-thread-sleep-stop-jtextfield-settext-working) answer your question? – Moritz Schmidt Nov 09 '20 at 17:03
  • 2
    What are variables `b1`,`b2` and `b3`? If they are `String`s, this is not the way to compare Strings. – George Z. Nov 09 '20 at 17:12
  • 2
    Method names should NOT start with an upper case character. – camickr Nov 09 '20 at 17:54

0 Answers0