(DM)用DRAW2D画多边形的例子

来源:百度文库 编辑:神马文学网 时间:2024/06/03 10:48:14
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();
}
}
}