SWT: double buffering

N

nickm687

Hi all,
I have created the below code using SWT very quickly which fades an
image. The problem is that it flickers very much ruining the effect.

Any ideas guys?

Regards
Nick

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class test2 {
Display display = new Display();
Shell shell = new Shell(display);

public static void main(String[] args) {
new test2();
}

public test2() {


shell.setLayout(new FillLayout());
shell.setSize(500, 500);
shell.open();
shell.pack();
ImageData imageData = new ImageData("logo.jpg");
// Image halfImage = new Image(display,imageData);
Canvas canvas1 = new Canvas(shell,SWT.DOUBLE_BUFFERED);
GC CGC = new GC(canvas1);

for (int i=255; i>=0; i = i-4) {
shell.setSize(500, 500);
canvas1.setSize(500,500);
CGC.fillRectangle(0, 0, 500, 500);
// display.update();
imageData.alpha = i;
CGC.drawImage(new Image(display,imageData), 0, 0);
display.update();
try {
Thread.sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
}
// imageData.alpha = 64;
// final Image quarterImage = new Image(display,imageData);
/**
Canvas canvas = new Canvas(shell,SWT.NO_REDRAW_RESIZE);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
// e.gc.drawImage(fullImage,0,0);
e.gc.drawImage(halfImage,140,0);
// e.gc.drawImage(quarterImage,280,0);

}
});


shell.setSize(500, 500);
shell.open();
shell.pack();
shell.setSize(500, 500);
//textUser.forceFocus();

// Set up the event loop.
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
// If no more entries in event queue
display.sleep();
}
}

display.dispose();
}



private void init() {

}

public static void main(String[] args) {
new test2();
}
}
**/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top