Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package helloWorld;
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.events.PaintEvent;
- import org.eclipse.swt.events.PaintListener;
- import org.eclipse.swt.graphics.Color;
- import org.eclipse.swt.graphics.GC;
- import org.eclipse.swt.layout.FillLayout;
- import org.eclipse.swt.widgets.Canvas;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.Group;
- import org.eclipse.swt.widgets.Shell;
- public class CanvasDemo {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new FillLayout());
- Group group = new Group(shell, SWT.SHADOW_ETCHED_IN);
- group.setText("My new masterpeice");
- group.setLayout(new FillLayout());
- Canvas canvas = new Canvas(group, SWT.NO_REDRAW_RESIZE);
- canvas.addPaintListener(new PaintListener() {
- @Override
- public void paintControl(PaintEvent e) {
- // TODO Auto-generated method stub
- GC gc = e.gc;
- Display display = e.display;
- Color Cyan = display.getSystemColor(SWT.COLOR_DARK_CYAN);
- gc.setForeground(Cyan);
- gc.drawLine(100, 100, 300, 300);
- gc.drawPolygon(new int[] {5, 10, 57, 67, 67, 67} );
- }
- });
- shell.open();
- while(!shell.isDisposed())
- if (!display.readAndDispatch())
- display.sleep();
- display.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement