Problème d'affichage d'un Graphe

Mchupakabra Messages postés 309 Date d'inscription lundi 12 mars 2007 Statut Membre Dernière intervention 11 septembre 2012 - 1 juin 2008 à 12:30
 Utilisateur anonyme - 4 juin 2008 à 01:47
Bonjour,
J'ai deux classes: la première s'appelle Graph et la seconde s'appelle cadre1
La classe Graph affiche un Graphe simple ( "Hello World")en utilisant JGraph (elle marche très bien)et la seconde est un Frame qui contient un Jbouton, ce que je veux faire, c'est afficher mon Graphe en appuyant sur le bouton, mais au lancement j'ai une exception de type :
java.lang.NoSuchMethodError: main
Exception in thread "main"
Voià mes deux classes et merci d'avance pour votre aide, et désolé c'est la premièrefois que je poste sue se forum et je n'arrive pas à trouver les balises code .
La classe Graph :
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);
}
}
Et voilà la classe cadre1 :
package sans_titre7;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Cadre1 extends JFrame {
JPanel contentPane;
JButton jButton1 = new JButton();

//Construire le cadre
public Cadre1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

//Initialiser le composant
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setBounds(new Rectangle(164, 108, 71, 23));
jButton1.setText("jButton1");
jButton1.addActionListener(new Cadre1_jButton1_actionAdapter(this));
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Titre du cadre");
contentPane.add(jButton1, null);
}

//Redéfini, ainsi nous pouvons sortir quand la fenêtre est fermée
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}

void jButton1_actionPerformed(ActionEvent e) {
Graph jjl = new Graph();
}
}

class Cadre1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Cadre1 adaptee;

Cadre1_jButton1_actionAdapter(Cadre1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}

1 réponse

Utilisateur anonyme
4 juin 2008 à 01:47
Bonjour,

Ce n'est pas un probleme d'affichage d'un graphe que tu as, mais bien un probleme de lancement. Java ne trouve pas de "main" .

Cordialement,

Dan.

...\ Dan /...
0
Rejoignez-nous