I wanted to create a calculator whose keys change color when pressed and return to their initial colors(white) after 3000 milliseconds. For that, I implemented the JButton.setBackground() method and wrote code to make the key revert to its original color after 3000 milliseconds. But instead, every time I click a calculator key, it waits 3000 ms before returning the JButton value to me, it changes color but it doesn't revert to its original color. I tried several maneuvers but without success. Here is my code for the JButton to change color for a given before returning to its initial color:
try {
buttonOne.setBackground(Color.RED) ;
Thread.sleep(millis:3000) ;
buttonOne.setBackground(Color.WHITE);
} catch (InterruptedException interruptedException ) {
InterruptedException.printStackTrace();
}