读书人

Draw2d 连线1

发布时间: 2012-11-08 08:48:12 作者: rapoo

Draw2d 连线一

关键字:Draw2d 连线 PolylineConnection

?

public class HelloWorld2 {public static void main(String args[]) {Shell shell = new Shell();shell.setText("Draw2d Hello World");shell.setSize(400, 400);shell.open();// create content 4 shell.createContent4Shell(shell);while (!shell.isDisposed ()) {if (!Display.getDefault().readAndDispatch ())Display.getDefault().sleep ();}}private static void createContent4Shell(Shell shell) {Panel rootFigure = new Panel();rootFigure.setLayoutManager(new XYLayout());IFigure figure1 = new Ellipse();IFigure figure2 = new Ellipse();//IFigure figure2 = new Triangle();// --------------------// add connectionPolylineConnection connection = new PolylineConnection();connection.setSourceAnchor(new ChopboxAnchor(figure1));connection.setTargetAnchor(new ChopboxAnchor(figure2));// add connection// --------------------rootFigure.add(figure1,new Rectangle(10,10,60,30));rootFigure.add(figure2,new Rectangle(80,90,60,30));rootFigure.add(connection);LightweightSystem lws = new LightweightSystem(shell);lws.setContents(rootFigure);}}

?

连线也是一个Figure也要加到父Figure中去,要指定连线的两个端点就行了。


Draw2d 连线1
?

?

读书人网 >软件架构设计

热点推荐