IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Java Discussion :

Problème pas trop compliqué


Sujet :

Langage Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Profil pro
    ghfhrghjyej
    Inscrit en
    Février 2007
    Messages
    87
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : Algérie

    Informations professionnelles :
    Activité : ghfhrghjyej

    Informations forums :
    Inscription : Février 2007
    Messages : 87
    Par défaut Problème pas trop compliqué
    Bonjour,
    J'ai un petit problème que je n'arrive pas à résoudre :
    Voilà j'ai deux classes une qui s'appelle Graph et qui utilise JGraph la voici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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);
      }
    }

    et l'autre qui s'appelle cadre1 la voilà :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    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);
      }
    }
    Donc mon problème est simple, j'ai mis dans cadre1 un jbouton, je voudrais que ce JButton fasse appelle à la classe Graph et qu'il la fasse apparaitre mais j'ai une excption au lancement de type :
    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Je tiens à préciser que ma classe Graph s'éxécute normalement et qu'elle affiche normalement si je fais directement appelle à elle.
    Merci d'avance pour votre aide.

  2. #2
    Membre Expert Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Par défaut
    L'erreur est assez parlante "NoSuchMethodError: main". Il n'y a pas de méthode main dans la classe que tu veux exécuter (tu ne peux donc pas l'exécuter);

  3. #3
    Membre actif
    Profil pro
    ghfhrghjyej
    Inscrit en
    Février 2007
    Messages
    87
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : Algérie

    Informations professionnelles :
    Activité : ghfhrghjyej

    Informations forums :
    Inscription : Février 2007
    Messages : 87
    Par défaut
    Oui effectivement j'ai changé la classe par une autre ayant une méthode main donc maintenant le programme compile normalement mais à l'affichage je n'ai rien.
    PS j'ai aussi changé le type de la classe Graphe (elle n'hérite plus de JFrame ).
    Voilà les deux nouvelles classes
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    package sans_titre7;
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class Cadre2 extends JFrame {
      JButton jButton1 = new JButton();
      GridBagLayout gridBagLayout1 = new GridBagLayout();
     
      public Cadre2() {
        try {
          jbInit();
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
      }
     
      void jbInit() throws Exception {
        jButton1.setText("jButton1");
        jButton1.addActionListener(new Cadre2_jButton1_actionAdapter(this));
        this.getContentPane().setLayout(gridBagLayout1);
        Graph jjl = new Graph();
        this.getContentPane().add(jButton1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(16, 140, 261, 189), 0, 0));
     
      }
     
      public static void main(String[] args) {
        Cadre2 cadre2 = new Cadre2();
        cadre2.setVisible(true);
        cadre2.setSize(1000,1000);
      }
     
      void jButton1_actionPerformed(ActionEvent e) {
    Graph jjl = new Graph();
     
      }
    }
     
    class Cadre2_jButton1_actionAdapter implements java.awt.event.ActionListener {
      Cadre2 adaptee;
     
      Cadre2_jButton1_actionAdapter(Cadre2 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
      }
    }
    et la classe Graph :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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   {
      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 {
     
      }
    }
    Je ne comprend pas, normalement quand je met Graph jjl = new Graph ();
    je doit voir la frame qui contient le graph, alors pourquoi n'apparait-elle pas ?

Discussions similaires

  1. Réponses: 25
    Dernier message: 02/04/2012, 20h42
  2. Réponses: 5
    Dernier message: 23/06/2004, 22h23
  3. pas si compliqué
    Par yamino dans le forum Langage SQL
    Réponses: 4
    Dernier message: 31/03/2004, 09h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo