gpt4 book ai didi

java - 在 JUNG 上重绘图形

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:33:44 25 4
gpt4 key购买 nike

我使用 JUNG(Java 通用网络/图形框架)构建一个图形,代码如下:

g = new SparseMultigraph<BusStop, Travel>();

//add some Vertex and Edges

Layout<String, String> layout1 = new CircleLayout(g);
layout1.setSize(new Dimension(300,300)); // sets the initial size of the layout space

VisualizationViewer vv = new VisualizationViewer(layout1);
vv.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size

Transformer<BusStop,Paint> vertexPaint = new Transformer<BusStop,Paint>() {
public Paint transform(BusStop b) {
return Color.GREEN;
}
};

Transformer<BusStop,Shape> vertexShape = new Transformer<BusStop,Shape>() {
public Shape transform(BusStop b) {
return new Rectangle(-20, -10, 40, 20);
}
};

vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getRenderContext().setVertexShapeTransformer(vertexShape);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

GraphViewerForm = new edu.uci.ics.jung.visualization.GraphZoomScrollPane(vv);

现在,我想向图中添加更多的顶点和边。我该怎么做?我应该运行什么指令来重绘图形?谢谢!

最佳答案

向图中添加边和顶点后,您必须调用vv.repaint() 来绘制更改。

关于java - 在 JUNG 上重绘图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6083623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com