Results 1 to 2 of 2
  1. #1
    darkthawt is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Question Help Please: SWT double buffering simple animation

    Hi forum members,

    I am trying to provide a double buffering to avoid flickering that I've gotten from Animate a bouncing ball with Double Buffering : Animation**SWT 2D Graphics**Java Tutorial

    But I would like to do this inside a Composite

    Java Code:
    public class MovingBall extends Composite {
    	
    	private Canvas canvas;
    	private Display display;
    	
    	private int x = 20;
    	private int y = 20;
    	
    	public MovingBall(Composite parent) {
    		super(parent, SWT.NONE);
    		display = parent.getDisplay();
    		
    		this.addPaintListener(new PaintListener() {
    			public void paintControl(PaintEvent event) {
    				// create image that may fill canvas
    				Image image = new Image(event.display, event.display.getBounds());
    
    				GC gcImage = new GC(image);
    				
    				gcImage.setBackground(event.gc.getBackground());
    				gcImage.fillOval(x,y, 20,20);
    				
    				// draw the image on screen
    				event.gc.drawImage(image, 0, 0);
    				
    				//clean up memory
    				image.dispose();
    				gcImage.dispose();
    				System.out.println("paintin");
    			}
    		});
    		
    		Thread thread = new Thread() {
    			public void run() {
    				long currentTime = System.currentTimeMillis();
    				int delayTime = 10;
    				while(currentTime + delayTime * 10 > System.currentTimeMillis()) {
    					
    				}// end while
    				display.asyncExec(new Runnable() {
    					public void run() {
    						animate();
    						System.out.println("I'm running");
    					}// end run
    				});// end asynExec
    			}// end run
    		};
    	}
    	
    	public void animate() {
    		x++;
    		y++;
    		this.redraw();
    	}
    }
    According to my code, the ball has not moved. And I would like any help that would point me to the right direction.

    Thanks

  2. #2
    darkthawt is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default

    Sorry but, I have found the solution to my problem. The code was missing two calls display.timeExec().

Similar Threads

  1. Double Buffering an Application?
    By Moncleared in forum New To Java
    Replies: 8
    Last Post: 09-14-2009, 05:45 AM
  2. Double Buffering
    By dunff2k in forum SWT / JFace
    Replies: 1
    Last Post: 11-14-2008, 04:26 PM
  3. [SOLVED] Double Buffering
    By Zosden in forum AWT / Swing
    Replies: 1
    Last Post: 07-24-2008, 03:28 AM
  4. Replies: 0
    Last Post: 06-28-2008, 10:23 PM
  5. Double Buffering problem
    By aprenz in forum Java Applets
    Replies: 0
    Last Post: 05-28-2008, 05:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •