The Artima Developer Community
Sponsored Link

Java Answers Forum
I am getting to much flickerence in applet

6 replies on 1 page. Most recent reply: May 19, 2003 8:40 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Ajay

Posts: 8
Nickname: aju
Registered: Apr, 2003

I am getting to much flickerence in applet Posted: May 12, 2003 10:25 PM
Reply to this message Reply
Advertisement
Can anybody help in reducing the flickerence problem that i am facing in applet. Actually i have mouse on over calling a function repaint(). is their any other way to reduce the prob of flickerence..
thanks


Alex S

Posts: 27
Nickname: andu
Registered: Mar, 2003

Re: I am getting to much flickerence in applet Posted: May 13, 2003 12:37 AM
Reply to this message Reply
Override update() method in your applet and do NOTHING in your implementation (Component's repaint() method is calling update() method).

And then tell me if it works :) because I never test it, but I heard that this might be the solution.

Ajay

Posts: 8
Nickname: aju
Registered: Apr, 2003

Re: I am getting to much flickerence in applet Posted: May 13, 2003 8:29 AM
Reply to this message Reply
> Override update() method in your applet and do NOTHING in
> your implementation (Component's repaint() method is
> calling update() method).
>
> And then tell me if it works :) because I never test it,
> but I heard that this might be the solution.

but i am not getting the graphics g to call update .. thats the problem. to call update it require g as grpahics object which i dont have other than the paint() method. I didnot get create thru createImages and then the getGraphics object.
SO thats the prob in my code.. pls tell me if i can have any other solution

Alex S

Posts: 27
Nickname: andu
Registered: Mar, 2003

Re: I am getting to much flickerence in applet Posted: May 14, 2003 2:04 AM
Reply to this message Reply
Applet class is extending Component class. update() method is defined in Component class. Did you try to override update() method in your class and do nothing there?

Like:

public MyApplet extends Applet {

void update(Graphics g){
//nothing here
}
}

You don't have to call update()!!! It is called automatically. Just override it.

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: I am getting to much flickerence in applet Posted: May 14, 2003 2:22 PM
Reply to this message Reply
Flicker in an applet is eliminated usually by double buffering.

declare two class variables:
Image offscreenimage;
Graphics offscreen;


In your init() method, initialize an offscreen graphics components for double buffering:

offscreenimage = createImage(appletwidth,appletheight);

in the applet paint method:

first do all the drawing that you normally do to the offscreen graphics context:

offscreen.setColor(Color.red);
offscreen.drawString("Test Test Test",250,30);
etc....

then draw the offscreen image produced to the onscreen graphics context specified in the argument of your paint method:

onscreen.drawImage(offscreenimage,0,0,this);

All the drawing which is currently causing the flickering, will be drwan to the ofscreen graphics, then the ofscreen graphics updated with the image of the offscreen graphics.
This last line occurs very fast, basically eliminating flicker.

Look at the code in:

http://www.quantumhyperspace.com/SourceBank/viewCode.jsp?javaFile=QuantumClock.java

which demonstrates double buffering.
There is probably some more on all this in the java tutorial.

Ajay

Posts: 8
Nickname: aju
Registered: Apr, 2003

Re: I am getting to much flickerence in applet Posted: May 19, 2003 12:00 AM
Reply to this message Reply
thanks for your valuable solution. I have implemented ur double buffering in my programe but it is still filckers the same. Actually i have a bar diagram if the mouse is on the any of the bar i need to repaint the applet. Pls if u have any other solution particular to my problem facing is heartily welcome..

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: I am getting to much flickerence in applet Posted: May 19, 2003 8:40 AM
Reply to this message Reply
Double buffering should have solved your flickered problem. Without seeing the code in your paint method, its hard to give any specific advice.

If you use swing components such as JApplet, double buffering comes as a default.

Flat View: This topic has 6 replies on 1 page
Topic: calander Previous Topic   Next Topic Topic: java exe file?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use