有个需求,jgraph后台生成了流程图,但是要放在JSP页面上展示,希望各位朋友能多支持,不吝赐教,万分感谢!!
解决方案 »
- myEclipse7.0中java为生成uml图
- 大家都来聊聊在什么项目中应用了Webservice,以及采用了哪个平台
- 关于ibator的几个简单问题。
- [500分]跪求spring2中用AspectJ开发的aop的可以使用的例子!
- javabean的equals问题解决办法? 在线等待!!!
- 关于jsp的问题
- struts中在页面上显示图片,使用绝对路径加struts标签
- 在线求助:为什么Result.getBlob()方法不能使用?
- weblogic 8.1 中的问题
- 关于java applet 嵌入web的解决办法
- 如何区分this.age 和 student.age
- J2ee目前适合开发哪类项目?适合建站吗?
servlet做io流输出,jsp里面用<image src="servlet"/>就行。
public class HelloWorld extends Applet{
public static void main(String[] args) {
GraphModel model = new DefaultGraphModel();
GraphLayoutCache view = new GraphLayoutCache(model,
new
DefaultCellViewFactory());
JGraph graph = new JGraph(model, view);
DefaultGraphCell[] cells = new DefaultGraphCell[3];
cells[0] = new DefaultGraphCell(new String("Hello")); GraphConstants.setBounds(cells[0].getAttributes(), new
Rectangle2D.Double(20,20,40,20));
GraphConstants.setGradientColor(
cells[0].getAttributes(),
Color.orange);
GraphConstants.setOpaque(cells[0].getAttributes(), true);
DefaultPort port0 = new DefaultPort();
cells[0].add(port0);
cells[1] = new DefaultGraphCell(new String("World")); GraphConstants.setBounds(cells[1].getAttributes(), new
Rectangle2D.Double(140,140,40,20));
GraphConstants.setGradientColor(
cells[1].getAttributes(),
Color.red);
GraphConstants.setOpaque(cells[1].getAttributes(), true);
DefaultPort port1 = new DefaultPort();
cells[1].add(port1);
DefaultEdge edge = new DefaultEdge();
edge.setSource(cells[0].getChildAt(0));
edge.setTarget(cells[1].getChildAt(0));
cells[2] = edge;
int arrow = GraphConstants.ARROW_CLASSIC; GraphConstants.setLineEnd(edge.getAttributes(), arrow);
GraphConstants.setEndFill(edge.getAttributes(), true);
graph.getGraphLayoutCache().insert(cells);
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);
}
}jsp页面
<HTML><TITLE>HelloWorld! Applet</TITLE><APPLETcodebase="."CODE="hello.HelloWorld.class"name="HelloWorld" WIDTH=200HEIGHT=100ALIGN = middle> </APPLET></HTML>
OutputStream os = response.getOutputStream();
if (img != null) {
try {
ImageIO.write(img, "JPEG", os);
os.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
os.close();
}
}
GraphModel model = new DefaultGraphModel();
GraphLayoutCache view = new GraphLayoutCache(model,
new DefaultCellViewFactory());
JGraph graph = new JGraph(model, view);
DefaultGraphCell[] cells = new DefaultGraphCell[3];
cells[0] = new DefaultGraphCell(new String("Hello"));
GraphConstants.setBounds(cells[0].getAttributes(),
new Rectangle2D.Double(20, 20, 40, 20));
GraphConstants.setGradientColor(cells[0].getAttributes(), Color.orange);
GraphConstants.setOpaque(cells[0].getAttributes(), true);
DefaultPort port0 = new DefaultPort();
cells[0].add(port0);
cells[1] = new DefaultGraphCell(new String("World"));
GraphConstants.setBounds(cells[1].getAttributes(),
new Rectangle2D.Double(140, 140, 40, 20));
GraphConstants.setGradientColor(cells[1].getAttributes(), Color.red);
GraphConstants.setOpaque(cells[1].getAttributes(), true);
DefaultPort port1 = new DefaultPort();
cells[1].add(port1);
DefaultEdge edge = new DefaultEdge();
edge.setSource(cells[0].getChildAt(0));
edge.setTarget(cells[1].getChildAt(0));
cells[2] = edge;
int arrow = GraphConstants.ARROW_CLASSIC;
GraphConstants.setLineEnd(edge.getAttributes(), arrow);
GraphConstants.setEndFill(edge.getAttributes(), true); graph.getGraphLayoutCache().insert(cells);
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);
}
}
页面:<html>
<head>
</head>
<body>
<applet codebase="."
archive="jgraph.jar"
code="hello.HelloWorld.class"
name="HelloWorld"
width="320"
height="240">
</applet>
</body>
</html>
访问页面时 ,流程图还是在跳出的窗口中显示,请各位高手帮助一下。怎么嵌入到页面中,而且在页面中也能拖拽啊?
public HelloWorld(){
GraphModel model = new DefaultGraphModel();
GraphLayoutCache view = new GraphLayoutCache(model,
new DefaultCellViewFactory());
JGraph graph = new JGraph(model, view);
DefaultGraphCell[] cells = new DefaultGraphCell[3];
cells[0] = new DefaultGraphCell(new String("Hello"));
GraphConstants.setBounds(cells[0].getAttributes(),
new Rectangle2D.Double(20, 20, 40, 20));
GraphConstants.setGradientColor(cells[0].getAttributes(), Color.orange);
GraphConstants.setOpaque(cells[0].getAttributes(), true);
DefaultPort port0 = new DefaultPort();
cells[0].add(port0);
cells[1] = new DefaultGraphCell(new String("World"));
GraphConstants.setBounds(cells[1].getAttributes(),
new Rectangle2D.Double(140, 140, 40, 20));
GraphConstants.setGradientColor(cells[1].getAttributes(), Color.red);
GraphConstants.setOpaque(cells[1].getAttributes(), true);
DefaultPort port1 = new DefaultPort();
cells[1].add(port1);
DefaultEdge edge = new DefaultEdge();
edge.setSource(cells[0].getChildAt(0));
edge.setTarget(cells[1].getChildAt(0));
cells[2] = edge;
int arrow = GraphConstants.ARROW_CLASSIC;
GraphConstants.setLineEnd(edge.getAttributes(), arrow);
GraphConstants.setEndFill(edge.getAttributes(), true); graph.getGraphLayoutCache().insert(cells);
Panel panel = new Panel();
panel.setSize(800000000, 60000000);
panel.add(new JScrollPane(graph));
this.add(panel);
}用此方法已解决
https://sourceforge.net/p/flowgraph