Skip to content

Instantly share code, notes, and snippets.

@davorb
Created September 3, 2012 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davorb/3608395 to your computer and use it in GitHub Desktop.
Save davorb/3608395 to your computer and use it in GitHub Desktop.
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SwtApp {
public SwtApp(final Display display) {
final Shell shell = new Shell(display);
shell.addPaintListener(new PaintListener(){
public void paintControl(PaintEvent e){
e.gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
e.gc.fillOval(10,10,100,100);
Font font = new Font(display,"Arial",22,SWT.BOLD);
e.gc.setFont(font);
e.gc.drawText("Hello",1,30, SWT.DRAW_TRANSPARENT);
font.dispose();
e.gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
e.gc.fillOval(40,40,100,100);
font = new Font(display,"Helvetica",22,SWT.ITALIC);
e.gc.setFont(font);
e.gc.drawText("Shoes!",30,60, SWT.DRAW_TRANSPARENT);
font.dispose();
}
});
shell.setSize(165, 185);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
public static void main(String[] args) {
Display display = new Display();
new SwtApp(display);
display.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment