To initialize my image, I have:
imageWater = Toolkit.getDefaultToolkit().getImage("water5.gif");
In my paintComponent() method, I have something like this:
g.drawImage(imageWater, 50, 50, 50, 50, this);
However, if I change the reference of imageWater to a different file than water5.gif, say, water6.gif, nothing else in the paintComponent() method works, even those that are completely unrelated to imageWater. I have tried changing both variables and references, and nothing works until I replace that exact file in that exact place. I do not understand why this is occurring.
My theory is that the thread.sleep I’ve been using does not perform well with paintComponent (or any gui in general) and I have merely been getting lucky for whatever reason before. I hesitate to test this because I have many thread.sleep() throughout the document and have no idea how to substitute them.
“My theory is that the thread.sleep I’ve been using does not perform well with paintComponent (or any gui in general” would be correct.
The fact hat you’ve not provided us with a working example to look at makes it difficult to understand what it is your are doing or what it is your trying to achieve.
Yu might like it have a look at
For more information on the topic and possible solutions