我正在尝试从MySQL数据库中检索2列。一列用于使用Jung创建顶点。在第二列中,我有2个值。我必须根据第二个字段中的值更改顶点大小。 编码部分:
try {
String query = "select GeneID, GenExpression from gene1 where Disease= 'Hereditery Breast Cancer '";
PreparedStatement pest = connection.prepareStatement(query);
ResultSet rs = pest.executeQuery();
while (rs.next()) {
name1[i] = rs.getString("GeneID");
g.addVertex(name1[i]);
name2[j] = rs.getString("GenExpression");
System.out.println(name2[j]);
i++;
j++;
}
rs.close();
pest.close();
我尝试使用以下代码。
ransformer<String, Paint> vertexPaint = new Transformer<String, Paint>() {
public Paint transform(String i) {
return Color.red;
}
};
Transformer<String, Shape> vertexSize = new Transformer<String, Shape>() {
public Shape transform(String x) {
Ellipse2D circle = new Ellipse2D.Double(-10, -10, 40, 40);
for (i = 0; i < name2.length; i++) {
for (j = 0; j < name2.length; j++) {
if (name2[j] == "Upregulated") {
AffineTransform.getScaleInstance(3, 3)
.createTransformedShape(circle);
} else {
AffineTransform.getScaleInstance(3, 3)
.createTransformedShape(circle);
}
}
}
return circle;
}
};
// 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<Integer, Stroke> edgeStrokeTransformer = new Transformer<Integer, Stroke>() {
public Stroke transform(Integer i) {
return edgeStroke;
}
};
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
// vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
vv.getRenderContext().setEdgeArrowStrokeTransformer(
edgeStrokeTransformer);
vv.getRenderContext().setVertexShapeTransformer(vertexSize);
vv.getRenderContext().setVertexLabelTransformer(
new ToStringLabeller<String>());
但尺寸并没有根据情况而改变。任何人都可以帮我这个吗?
答案 0 :(得分:0)
您的代码至少有两个问题:
(1)您正在创建形状的转换副本,但您没有将该副本用于任何内容
(2)您所申请的转型在所有情况下均相同,因此不会有任何差异。
我不知道您的数据(基于您选择要执行哪个转换的数据)是否设置正确,但这是另一个可能的错误来源。