Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using an image in an applet

Status
Not open for further replies.

red22j

Programmer
Aug 1, 2002
10
0
0
US
Basically, what I want to do is have an applet with a background image. The problem is when I try to make a certain control invisible, I don't know how to refresh the image so that it now paints the part of the image where the control was. Right now, when the control disappears I see the background color of the applet rather than the part of the image that should be there. The only way I know how to redraw the image is to redraw the entire image using drawImage(), but then I have to redraw all the controls as well and this creates a flicker.

Any suggestions will be greatly appreciated,
thanks
Jonathan
 
are you getting this flicker because you simply don't have the power to build the whole screen up every frame, or is it because the refreshes aren't timed correctly?

writting an engine that refreshes only part of the screen can be a nightmare to write. you need to work out what part of the screen needs updating (if a rectangular thing has been moved, then it should leave a space that can be filled by no more than two rectangles), then you need to instance the apropriate section of background picture and place it apropriatly.

the thing to remember though, is that you wuld also have to rewrite the method that refreshes the screen, as this would probably build everything from scratch anyway; which leads me to think that you might just want to think about when you are refreshing, rather than what you are refreshing.

i assume you are currently running a program loopy that goes - do some stuff > refresh. try just doing stuff all the time, and having a seperate thread to call the refresh method every so often.

import javax.swing.*;
...
public class prog...
Timer t;
...
public prog(){
ActionListener a = new ActionListener(){
public void actionPerformed(ActionEvent e){
//refresh stuff here
}
};
t = new Timer(20, a);//20ms = 50fps
t.start();


if this doesn't suit your situation, post a code snippet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top