急急急 如何让Jgraph生成的流程图显示到web页面上 有个需求,jgraph后台生成了流程图,但是要放在JSP页面上展示,希望各位朋友能多支持,不吝赐教,万分感谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不是太了解Jgraph,你查查api有没有可以输出为io流的东西?servlet做io流输出,jsp里面用<image src="servlet"/>就行。 我用过两种方案,一是applet,一是生成静态图片。jbpm有生成静态图片的例子,可以参考 请指教,我对Applet不了解 请问哪里写错了,我怎么显示不出来啊在页面public class HelloWorld extends Applet{public static void main(String[] args) {GraphModel model = new DefaultGraphModel();GraphLayoutCache view = new GraphLayoutCache(model,newDefaultCellViewFactory());JGraph graph = new JGraph(model, view);DefaultGraphCell[] cells = new DefaultGraphCell[3];cells[0] = new DefaultGraphCell(new String("Hello")); GraphConstants.setBounds(cells[0].getAttributes(), newRectangle2D.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(), newRectangle2D.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> applet不需要main方法,需要init等方法,自己找个applet的例子吧 做成静态图片,通过action或者servlet输出到页面就可以了 已经可以页面上显示了,用的静态图片方式,不能拖拽,代码在下方 。 我想做成一个可以拖拽布局的,就和它原来桌面程序一样,不知道使用applet能否实现此功能。BufferedImage img = graph.getImage(graph.getBackground(), 1); OutputStream os = response.getOutputStream(); if (img != null) { try { ImageIO.write(img, "JPEG", os); os.flush(); } catch (Exception e) { e.printStackTrace(); } finally { os.close(); } } 按说进将桌面程序里的jgraph图像代码搬到applet中去就可以了,记得指定jgraph的jar包 public class HelloWorld extends Applet { public void init() { 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 class HelloWorld extends Applet { 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);}用此方法已解决 怎么解决的啊,我也在学这个,。jgraph画拓扑图在页面显示,页面用applet做,像客户端,有数据库连接,可以拖拽改变拓扑图保存到数据库。有谁做个这样的例子啊。 flowGraph,很简单的生成流程图,可以看看https://sourceforge.net/p/flowgraph Hibernate的HQL查询数据库的数据表字段名问题 求救,jdbc查询时报异常~急!!! 鼠标控制 急!系统在windows下运行正常,linux下运行报错~~~~~~~ jgraph如何编写 工作流的做图软件 高手帮帮我看个程序 推荐一个介绍开源项目网站 请问在struts中这个是如何做的?(新手,请见谅) java面试前要注意哪些问题? 有没有将一个XML文档转换为一棵JTree显示的例子,拜托拜托! 如何区分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