Menu

=?utf-8?Q?Heelp_!!?=

2015-03-23
2015-03-23
  • bounil bilel

    bounil bilel - 2015-03-23

    Hello

    in order to create a multigraph I used the JUNG Library (and the same tutorial code )but while coding i received this problem "type graph does not take parameters" in this line “ Graph<Integer, String=""> g;
    and i can't find any solution to solve the problem in this code :

    import edu.uci.ics.jung.algorithms.layout.CircleLayout;
    import edu.uci.ics.jung.algorithms.layout.Layout;
    import edu.uci.ics.jung.graph.Graph;
    import edu.uci.ics.jung.graph.SparseMultigraph;
    import edu.uci.ics.jung.visualization.BasicVisualizationServer;
    import edu.uci.ics.jung.visualization.layout.*;
    import java.awt.Dimension;
    import javax.swing.JFrame;

    public class Simpleg {

    Graph<Integer, String=""> g;
    /* Creates a new instance of SimpleGraphView /
    public Simpleg() {
    // Graph<V, E=""> where V is the type of the vertices and E is the type of the edges
    g = new SparseMultigraph<Integer, String="">();
    // Add some vertices. From above we defined these to be type Integer.
    g.addVertex((Integer)1);
    g.addVertex((Integer)2);
    g.addVertex((Integer)3);
    // Note that the default is for undirected edges, our Edges are Strings.
    g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
    g.addEdge("Edge-B", 2, 3);
    }

    public static void main(String[] args) {
    Simpleg sgv = new Simpleg(); //We create our graph in here
    // The Layout<V, E=""> is parameterized by the vertex and edge types
    Layout<Integer, String=""> layout = new CircleLayout(sgv.g);
    layout.setSize(new Dimension(300,300)); // sets the initial size of the layout space
    // The BasicVisualizationServer<V,E> is parameterized by the vertex and edge types
    BasicVisualizationServer<Integer,String> vv = new BasicVisualizationServer<Integer,String>(layout);
    vv.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size

    JFrame frame = new JFrame("Simple Graph View");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv); 
    frame.pack();
    frame.setVisible(true);
    

    }

    }

    can you help me please

    Envoyé depuis Windows Mail

     
    • Sachin

      Sachin - 2015-03-23

      Following code works perfectly.
      I really don't understand why have you put ="" after String
      for each edge type parameter.
      I am using java 6 where ="" results an error but not otherwise.

      import edu.uci.ics.jung.algorithms.layout.CircleLayout;
      import edu.uci.ics.jung.algorithms.layout.Layout;
      import edu.uci.ics.jung.graph.Graph;
      import edu.uci.ics.jung.graph.SparseMultigraph;
      import edu.uci.ics.jung.visualization.BasicVisualizationServer;
      import edu.uci.ics.jung.visualization.layout.*;
      import java.awt.Dimension;
      import javax.swing.JFrame;

      public class Simpleg {

      Graph<Integer, String=""> g;
      / Creates a new instance of SimpleGraphView /
      public Simpleg() {
      // Graph<V, E=""> where V is the type of the vertices and E is the type of the edges
      g = new SparseMultigraph<Integer, String="">();
      // Add some vertices. From above we defined these to be type Integer.
      g.addVertex((Integer)1);
      g.addVertex((Integer)2);
      g.addVertex((Integer)3);
      // Note that the default is for undirected edges, our Edges are Strings.
      g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
      g.addEdge("Edge-B", 2, 3);
      }

      public static void main(String[] args) {
      Simpleg sgv = new Simpleg(); //We create our graph in here
      // The Layout<V, E=""> is parameterized by the vertex and edge types
      Layout<Integer, String=""> layout = new CircleLayout(sgv.g);
      layout.setSize(new Dimension(300,300)); // sets the initial size of the layout space
      // The BasicVisualizationServer<V,E> is parameterized by the vertex and edge types
      BasicVisualizationServer<Integer,String> vv = new BasicVisualizationServer<Integer,String>(layout);
      vv.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size

      JFrame frame = new JFrame("Simple Graph View");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.getContentPane().add(vv);
      frame.pack();
      frame.setVisible(true);

      }

       

      Last edit: Sachin 2015-03-23

Log in to post a comment.