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 {
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();
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");
}
}