1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
package sans_titre7;
import java.awt.geom.Rectangle2D;
import java.util.*;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultCellViewFactory;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;
import javax.swing.*;
import java.awt.*;
import com.borland.jbcl.layout.*;
public class Graph extends JFrame {
VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
public static void main(String[] args) {
ArrayList facti = new ArrayList();
matriceincidence mat = new matriceincidence(15,7);
for (int i=0;i<3;i++){
mat.affectervaleurentrée(mat,0,i,true);
}
for (int i=3;i<5;i++){
mat.affectervaleurentrée(mat,2,i,true);
}
for (int i=5;i<7;i++){
mat.affectervaleurentrée(mat,5,i,true);
}
int col = 0;
for(int i=1;i<15;i = i+2){
mat.affectervaleursortie(mat,i,col,true);
mat.affectervaleursortie(mat,i+1,col,true);
col++;
}
// facti.add(ootlook,rainy,windy,false, yes,ootllok,rainy,windy ,true,no,ootlok,overcast,yes,ottlook,sunny,normale,yes,otlook, sunny, élevée,no);
facti.add("visibilité");
facti.add("pluie");
facti.add("vent");facti.add("ouivent");
facti.add("jouer");facti.add("visibilité");facti.add("pluie");
facti.add("vent");
facti.add("pasvent");
facti.add( " pasjouer");facti.add("visibilité");facti.add("couvert");facti.add("jouer");
facti.add("visibilité");facti.add("soleil");facti.add("humidité");
facti.add("normale");facti.add("jouer");
facti.add("visibilité");facti.add("soleil");
facti.add("humidité");facti.add("élevée");facti.add("pas jouer");
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(facti.get(0));
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(facti.get(2));
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(facti.get(1));
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("L'Arbre de décision");
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);
}
public Graph() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(verticalFlowLayout1);
}
} |
Partager