color only changes, when resizng frame with mouse, not when clicking.
I assume you mean the color doesn't change when you click the button. This is because you didn't add the ActionListener to the button. You need:
The code in your paintComponent() method is wrong.
You should never change the state of a component in a painting method. That is resizing the frame should NOT affect the color.
To fix this problem all the random color code should be moved to the ActionListener:
Then the painting code should be: