At below, its my code to make a renewable graphics shows life game itself.
public paint(Graphics g)
{
g.setClip();//Set
g.setColor(Color.BLACK);
Processing.....
while(true)
{
g.clearRect();//Clear
g.drawLine(); //Draw;
Calling SwingWorking to prepare next statement
}
}
seems it's stupid to do like this way because when running it, the frame keep flashing and laggy.
I try to use Thread.sleep()
, but it just slow down the frequency of flash.
So, my problem is how to make it well and avoid flashing. The parts of code that I don't put on are all about data processing for instance variables, if you need it,please notice me, much appreciate for help.
Thanks, @MadProgrammer
Here is what I got, first, the flash is because when program calling repaint() and paint(), it cost too much time to make animation smoothly, in this case is clearRect() and drawLine().
I'll use double buffered to solve it.
Update,
Thanks guys, I read those examples. I just use a frame without any buffer method to show graphics before, what a mistake. I used bufferStrategy to solve it.