public class Polygon{ public static void main(String[] args) { final Display display = Display.getDefault(); final Shell shell = new Shell(); shell.setSize(500, 375); shell.setText("SWT Application"); LightweightSystem lws = new LightweightSystem(shell); Figure contents = new Figure(); XYLayout contentsLayout = new XYLayout(); contents.setLayoutManager(contentsLayout); Polygon p1 = new Polygon(); PointList list = new PointList(); list.addPoint(160, 0); list.addPoint(240, 80); list.addPoint(320, 80); list.addPoint(240, 0); p1.setPoints(list); p1.setBackgroundColor(display.getSystemColor(SWT.COLOR_BLUE)); contents.add(p1); p1.setFill(true);//使设置背景色生效【p1.setBackgroundColor(display.getSystemColor(SWT.COLOR_BLUE)); 】 lws.setContents(contents); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } } |
|