如何更正此代码 [英] how to correct this code
本文介绍了如何更正此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好每个人都请帮忙:
这是我的java代码,它使parcour成为一个xml文件来检索数据并使用图表api jgraph构建这些数据
我将代表Jframe中的图形
结果我得到的只是空的JFrame
似乎它没有运行第一条指令
hello every one help please :
Here is my java code that makes parcour an xml file to retrieve data and build with these data with a graph api jgraph
I will represent the graph in a Jframe
the result I get only empty JFrame
it seems it does not run the first instructions
import java.awt.BorderLayout;
import java.io.File;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.mxgraph.util.mxConstants;
import com.mxgraph.view.mxGraph;
import com.mxgraph.model.mxGeometry;
import com.mxgraph.swing.mxGraphComponent;
public class Tester extends JFrame {
/** Pour éviter un warning venant du JFrame */
private static final long serialVersionUID = -8123406571694511514L;
public static void main(String[] args) {
System.out.println("Bonjour");
try {
File nomf = new File("C:/Users/Hela/Desktop/1_auto.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(nomf);
doc.getDocumentElement().normalize();
System.out.println("Bonjour");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
//System.out.println("root of xml file" + doc.getDocumentElement().getNodeName());
NodeList nodes = doc.getElementsByTagName("triplet");
System.out.println("==========================");
Object racine= graph.insertVertex(parent, null,"brad pit", 20, 20, 80, 30);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
Object obj1 =graph.insertVertex(parent, null,getValue("object", element) , 20, 20, 80, 30,
mxConstants.STYLE_SHAPE + "="+mxConstants.SHAPE_ELLIPSE);
graph.insertEdge(parent, null,getValue("predicate", element) , racine, obj1);
}
}}
catch (Exception ex) {
ex.printStackTrace();}
finally {
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
getContentPane().add(graphComponent);
}
private static String getValue(String tag, Element element) {
NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
Node node = (Node) nodes.item(0);
return node.getNodeValue();
}
JPanel contentPane;
Graphe frame = new Graphe();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 320s);
frame.setVisible(true);
frame.setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
System.out.println("Bonjour");
}
}
推荐答案
这篇关于如何更正此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文