Здравствуйте!У меня проблема с моей программой.Я использую библиотеки JUNG в Java, и когда я компилирую программу, я получаю эти две ошибки:
Error:(43, 61) java: incompatible types: org.apache.commons.collections15.Transformer<java.lang.Integer,java.awt.Paint> cannot be converted to com.google.common.base.Function<? super java.lang.Integer,java.awt.Paint>
Error:(44, 56) java: incompatible types: org.apache.commons.collections15.Transformer<java.lang.String,java.awt.Stroke> cannot be converted to com.google.common.base.Function<? super java.lang.String,java.awt.Stroke>
Я не знаю, что эти ошибки могут означать для несовместимых типов данных.Как я могу решить проблему?Заранее спасибо!
Класс "GraphView":
import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.renderers.Renderer;
import org.apache.commons.collections15.Transformer;
import javax.swing.*;
import java.awt.*;
public class GraphView {
public GraphView() {
GraphBuilding gb = new GraphBuilding(); // This builds the graph
// Layout<V, E>, BasicVisualizationServer<V,E>
Layout<Integer, String> layout = new CircleLayout(gb.g);
layout.setSize(new Dimension(300, 300));
BasicVisualizationServer<Integer, String> vv =
new BasicVisualizationServer<Integer, String>(layout);
vv.setPreferredSize(new Dimension(350, 350));
// Setup up a new vertex to paint transformer...
Transformer<Integer, Paint> vertexPaint = new Transformer<Integer, Paint>() {
public Paint transform(Integer i) {
return Color.GREEN;
}
};
// Set up a new stroke Transformer for the edges
float dash[] = {10.0f};
final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
Transformer<String, Stroke> edgeStrokeTransformer =
new Transformer<String, Stroke>() {
public Stroke transform(String s) {
return edgeStroke;
}
};
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
JFrame frame = new JFrame("Custom Graph View");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
}
}
Класс "GraphBuilding":
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseGraph;
import edu.uci.ics.jung.graph.util.EdgeType;
public class GraphBuilding {
// Graph<V, E> where V is the type of the vertices
// and E is the type of the edges
public Graph<String, String> g = new SparseGraph<String, String>();
public GraphBuilding() {
// Add some vertices. From above we defined these to be type Integer.
g.addVertex("A");
g.addVertex("B");
g.addVertex("C");
// Add some edges. From above we defined these to be of type String
// Note that the default is for undirected edges.
g.addEdge("Edge-1", "A", "B", EdgeType.DIRECTED); // Note that Java 1.5 auto-boxes primitives
g.addEdge("Edge-2", "B", "C", EdgeType.DIRECTED);
// Let's see what we have. Note the nice output from the
// SparseMultigraph<V,E> toString() method
System.out.println("The graph g = " + g.toString());
}
}
Класс «Главный»:
public class Main {
public static void main(String[] args) {
new GraphView();
}
}