Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

AWT flicker

843799Jul 15 2001 — edited Aug 6 2001
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
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 ....
1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 3 2001
Added on Jul 15 2001
1 comment
76 views