Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Applet Repaint Issues
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
smaxd




PostPosted: Fri Mar 02, 2012 7:07 pm   Post subject: Applet Repaint Issues

When I translate this shape the graphics object doesn't clear the last frame of said shape.
Im trying to make that one shape move, not a line. Im not sure on how to stop this bug from happening,
any help would be greatly appreciated.
code:
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import javax.swing.JApplet;


public class Test extends JApplet {
        private Rectangle shape = new Rectangle(20,20,20,20);
        private Graphics g2;
        /**
         * Create the applet.
         */
        public Test() {
                Move ti = new Move();
                ti.start();
        }
       
        public void paint(Graphics g){
                Graphics2D g2 = (Graphics2D) g;
                g2.fill(shape);
        }
       
        private class Move extends Thread{
               
                public void run(){
                        try{
                                for(int x=  0; x<1000;x++){
                                        shape.translate(1, 1);
                                        sleep(1);
                                        repaint();
                                }
                               
                        } catch (Exception e){
                               
                        }
                }
        }

}
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Fri Mar 02, 2012 8:46 pm   Post subject: RE:Applet Repaint Issues

Well that's what you're telling it to do. In order to clear the shape from the last frame, you have to erase it. Usually what you do is at the start of the frame, you fill the background however you want, which will erase anything from the previous frame. Then you redraw your scene. Once you do this, you'll start noticing flickering. That's when you look up double buffering. Smile
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: