YoussefGamil Posted December 29, 2005 Share Posted December 29, 2005 Hi,I have a small problem in RE-draw any image!I mean when I replace any image with other the screen goes white for a sec then the other image appears.thanks,.. Link to comment Share on other sites More sharing options...
Tim_Tayler Posted January 16, 2006 Share Posted January 16, 2006 (edited) Moin Moin,i hope i'm not too late. Look at this...public class PetePanel extends JPanel implements Runnable{ MediaTracker tracker; Image[] petePics = new Image[6]; Image back; public PetePanel() { setBackground(Color.black); String[] peteScr = {"right1.gif", "right2.gif", "right3.gif", "stop.gif" , "blink.gif", "wave.gif"}; Toolkit kit = Toolkit.getDefaultToolkit(); tracker = new MediaTracker(this); for (int i = 0; i < petePics.length; i++) { petePics[i] = kit.getImage(peteScr[i]); tracker.addImage(petePics[i], i+1); } back = kit.getImage("backdrop.gif"); tracker.addImage(back, 0); } public void paintComponent(Graphics comp) { Graphics2D comp2D = (Graphics2D) comp; if(back != null) comp2D.drawImage(back, 0, 0, this); comp2D.setColor(Color.black); comp2D.fillRect(0, 30, 450, 30); if(petePics[current] != null) comp2D.drawImage(petePics[current], x, y, this); } . . .}in the main or run function call at first try { tracker.waitForAll(); } catch (InterruptedException ign) {}Thats it.cu Edited January 16, 2006 by Tim_Tayler Link to comment Share on other sites More sharing options...
YoussefGamil Posted February 9, 2006 Author Share Posted February 9, 2006 THANKS VERY MUCH I have used :repaint(X,Y,W,H);to re-draw the images Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now