Solved

Image flicker

Posted on 2002-06-05
5
275 Views
Last Modified: 2010-03-31
I have written an applet that does banner rotation. The only thing is that the banners flicker, as though they are being redrawn by clearing to the background first. It doesn't matter whether the banner is animated of not and it is not occuring at the point when the banner image is changed.

My paint method looks as follows

     public void paint(Graphics g)
     {
          Image image=getImage(u[current_image]);
          g.drawImage(image,0,0,this);
     }

Just to make sure I used Mediatracker to ensure the image was loaded, but this had no effect.

Any clues how I can overcome this?
0
Comment
Question by:mouatts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 50 total points
ID: 7057489
In your applet, you need to override the update method. In the same class that contains the paint method, provide an override for the update method like:

public void update(Graphics g)
{   paint(g);
    return;
}


This needs to be done to avoid the flicker because the default update does exactly what you suspected. It clears the image by redrawing the background first.
0
 
LVL 11

Author Comment

by:mouatts
ID: 7058268
Thanks that sort of did the trick, there was another wrinkle that someone else might have mentioned had you not locked the question!
0
 
LVL 16

Expert Comment

by:imladris
ID: 7059476
For the sake of the value of the PAQ's, it would be nice if you mentioned what the wrinkle was.

If you dislike questions being "locked" (which does not in fact prevent anyone from adding comments), you could mention that in the question or reject the answer.

The guideline for answers below notes that an answer should be "a specific solution to a question ... [that] will solve the questioner's problem and doesn't duplicate a previous comment".
The answer I gave obviously did not duplicate a comment, and it was my conviction that it would solve your problem. There is always the possibilty that I am wrong, of course, which is why you have access to the "reject answer" button.
0
 
LVL 16

Expert Comment

by:imladris
ID: 7059486
P.S. there is an extensive debate on the topic of answers and comments at: http://www.experts-exchange.com/expinput/Q_20304200.html .
0
 
LVL 11

Author Comment

by:mouatts
ID: 7059529
You've been on EE long enough to know that locking questions is frowned on by the vast majority of members.

The wrinkle is of course dealing with the situation when you do want to repaint the background. The answer of course being to use super.update(g) on those occasions.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question