Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. package helloWorld;
  2.  
  3. import org.eclipse.swt.SWT;
  4. import org.eclipse.swt.events.PaintEvent;
  5. import org.eclipse.swt.events.PaintListener;
  6. import org.eclipse.swt.graphics.Color;
  7. import org.eclipse.swt.graphics.GC;
  8. import org.eclipse.swt.layout.FillLayout;
  9. import org.eclipse.swt.widgets.Canvas;
  10. import org.eclipse.swt.widgets.Display;
  11. import org.eclipse.swt.widgets.Group;
  12. import org.eclipse.swt.widgets.Shell;
  13.  
  14. public class CanvasDemo {
  15.  
  16. public static void main(String[] args) {
  17. // TODO Auto-generated method stub
  18.  
  19. Display display = new Display();
  20. Shell shell = new Shell(display);
  21. shell.setLayout(new FillLayout());
  22.  
  23.  
  24. Group group = new Group(shell, SWT.SHADOW_ETCHED_IN);
  25. group.setText("My new masterpeice");
  26.  
  27.  
  28. group.setLayout(new FillLayout());
  29. Canvas canvas = new Canvas(group, SWT.NO_REDRAW_RESIZE);
  30.  
  31.  
  32. canvas.addPaintListener(new PaintListener() {
  33.  
  34. @Override
  35. public void paintControl(PaintEvent e) {
  36. // TODO Auto-generated method stub
  37. GC gc = e.gc;
  38.  
  39. Display display = e.display;
  40. Color Cyan = display.getSystemColor(SWT.COLOR_DARK_CYAN);
  41. gc.setForeground(Cyan);
  42. gc.drawLine(100, 100, 300, 300);
  43. gc.drawPolygon(new int[] {5, 10, 57, 67, 67, 67} );
  44.  
  45.  
  46.  
  47.  
  48.  
  49. }
  50. });
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. shell.open();
  62. while(!shell.isDisposed())
  63. if (!display.readAndDispatch())
  64. display.sleep();
  65.  
  66.  
  67. display.dispose();
  68.  
  69.  
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement