java - Swing - stop image from blinking -


i have been practicing java's swing features recently, , in 1 of classes extends class jpanel, have overriden method paintcomponent() paint bufferedimage onto jpanel. have method on move around. before issue, have had problem shows process of moving repaints quickly. so, created boolean variable called available set false when image still in moving process. but, see screen taking away entire image , putting back, causing blink. here basic pseudocode:

class extends jpanel{     bufferedimage canvas;     public a(){         //create image here     }     public move(){         available = false;         //move things around in here         available = true;     }     @override     protected void paintcomponent(graphics g){         super.paintcomponent(g);         if(available){             g.drawimage(this.canvas, 0, 0, null);         }         g.dispose();     } } class b{     public static void main(string[] args){         //construct class jpanel         while(some_variable){             class_a_jpanel.repaint();         }     } } 

this old topic fixed in modern java. prefer old way use old techniques. example double buffering


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -