2013-08-27 82 views
0

我嘗試通過Graphstream在java中構造圖。我想要有兩種類型的節點,其形狀默認爲圓形或框。因此分配給類代碼nodes.The:如何將類分配給圖流中的節點

System.setProperty("org.graphstream.ui.renderer","org.graphstream.ui.j2dviewer.J2DGraphRenderer"); 
Graph g1= new MultiGraph("db"); 
g1.addAttribute("ui.stylesheet", "ui.label"," node.att{shape:box;}"); 
Node n1 = g1.addNode("a"); 
n1.setAttribute("ui.class","att"); 
g1.display(); 

但在顯示該節點沒有框和是圓與在輸出該消息:

「與樣式表規範錯誤做什麼用「[Ljava .lang.Object; @ 192b996'?「

我在哪裏錯了? 感謝您的幫助。

回答

1
import javax.swing.JFrame; 
import javax.swing.JPanel; 

import org.graphstream.graph.*; 
import org.graphstream.graph.implementations.*; 
import org.graphstream.ui.spriteManager.Sprite; 
import org.graphstream.ui.spriteManager.SpriteManager; 
import org.graphstream.ui.swingViewer.View; 
import org.graphstream.ui.swingViewer.Viewer; 

public class Main { 
    /** 
    * @param args 
    */ 
    public static void main(String[] args) { 
     Graph graph = new MultiGraph("graph"); 

     String styleSheet="node {"+ 
    " fill-color: grey;"+ 
    " size: 10px;"+ 
    " stroke-mode: plain;"+ 
    " stroke-color: black;"+ 
    " stroke-width: 1px;"+ 
    "}"+ 
    "node.important {"+ 
    " fill-color: red;"+ 
    " size: 30px;"+ 
    "}"; 

     graph.addNode("A"); 
     graph.addNode("B"); 
     graph.addEdge("AB", "A", "B"); 
     Node e1=graph.getNode("A"); 
     graph.addAttribute("ui.stylesheet", styleSheet); 

     e1.addAttribute("ui.class", "important"); 
     e1.addAttribute("ui.label", "A Node"); 
     //e1.addAttribute("ui.hide"); 

     graph.display(); 
    } 

} 
相關問題