This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,899 Users
  • 2,269,649 Discussions
  • 7,916,821 Comments

Discussions

AWT flicker

843799
843799 Member Posts: 49,999
edited Aug 6, 2001 10:26AM in Java 3D
Hello everybody !
can somebody tell me ways to reduce awt flicker. It is becoming difficult to give real life touch to all those animations in applet.I have used both the versions of repaint().copyarea gives better results but it may not always be possible to use it.

Comments

  • 843799
    843799 Member Posts: 49,999
    I think you're in the wrong forum, baby.

    But here is a solution:
    	private Image bImage;
    	private Graphics bGraphics;
    	private int oldW;
    	private int oldH;
    
    
    	public void update(Graphics g){
    		paint(g);
    	}
    
    	public void paint(Graphics g){
    		if(getSize().width!=oldW || getSize().height!=oldH || bImage==null || bGraphics==null)
    			resetBuffer(getSize().width,getSize().height,this);
    
    		bGraphics.setColor(getBackground());
    		bGraphics.fillRect(0,0,oldW,oldH);
    		paintBuffer(bGraphics);
    		g.drawImage(bImage,0,0,this);
    	}
    
    	public void resetBuffer(int w,int h,Component c){
    		if(bGraphics!=null){
    			bGraphics.dispose();
    			bGraphics=null;
    		}
    
    		if(bImage!=null){
    			bImage.flush();
    			bImage=null;
    		}
    
    		System.gc();
    
    		bImage=c.createImage(w,h);
    		bGraphics=bImage.getGraphics();
    		oldW=w;
    		oldH=h;
    	}
    
    	public void paintBuffer(Graphics g){
    		//	ADD YOUR NORMAL PAINT-CODE HERE
    
    	}
    Hope I helped ....
This discussion has been closed.