Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1395 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  [Java] Bizarerie du MouseListener

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Java] Bizarerie du MouseListener

n°315039
djok_fb
C'était mieux avant!
Posté le 21-02-2003 à 15:46:48  profilanswer
 

Lut a tous...
 
voila, mon probleme:
J'ai créé une interface graphique qui ouvrent plusieurs fenetres(6 en tout)
 
2 de ces fenetres implementent l'interface MouseListener
 
la premiere fonctionne parfaitement (pour les 2, j'ai juste besoin du MouseClicked) mais l'autre me revoie une NullPointerException au moindre clic:
 
java.lang.NullPointerException
        at CDebugFrame.mouseClicked(CDebugFrame.java:64)
        ....
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

 
le probleme vient il du fait qu'on a pas le droit de faire 2 implements du MouseListener?
 
(ce sont des mouselistener sur des JList)

mood
Publicité
Posté le 21-02-2003 à 15:46:48  profilanswer
 

n°315049
BifaceMcLe​OD
The HighGlandeur
Posté le 21-02-2003 à 16:01:08  profilanswer
 

Absolument pas.
 
Mais si tu nous postais le code de ta classe CDebugFrame autour de la ligne 64, on devrait pouvoir t'aider un peu plus.

n°315053
djok_fb
C'était mieux avant!
Posté le 21-02-2003 à 16:06:18  profilanswer
 

ici le code de création de la JList:

Code :
  1. body = new JList(bodyV = loadInfoFromDebugXML());
  2. body.addMouseListener(this);


 
Voila, le code ligne 64:
 

Code :
  1. public void mouseClicked(MouseEvent e)
  2. 64->   {
  3.       if (!(body.isSelectionEmpty()))
  4.       {
  5.          int index = body.getSelectedIndex();
  6.          envDisp.currentInstr=index;
  7.          envDisp.setMainListVector();
  8.       }
  9.    }
  10.  
  11.    public void mouseEntered(MouseEvent e) {}
  12.    public void mouseExited(MouseEvent e) {}
  13.    public void mousePressed(MouseEvent e) {}
  14.    public void mouseReleased(MouseEvent e) {}


 
si c'etait un pb de { }, ca compilerait pas...surtout que l'autre MouseListener fonctionne (il a la meme gueule)

n°315072
BifaceMcLe​OD
The HighGlandeur
Posté le 21-02-2003 à 16:29:35  profilanswer
 

Tu es sûr que bodyV n'est pas nul ?
Si ce n'est pas le cas, je vais devoir te demander de m'envoyer ton code, parce que comme ça, je ne vois pas...  :??:

n°315077
djok_fb
C'était mieux avant!
Posté le 21-02-2003 à 16:36:29  profilanswer
 

malheureusement non, bodyV, il est pas "null", sinon, il n'y aurait rien dans ma JList...hors la, elle affiche tout un tas de truc (enfin, elle contient ce qu'elle doit contenir)
 
j'ai pensé a autre chose, la derniere ligne du truc d'erreur, c'est un plantus du run d'un thread, j'aurais atteind le maximum de thread possible?

n°315106
BifaceMcLe​OD
The HighGlandeur
Posté le 21-02-2003 à 17:14:53  profilanswer
 

Ca m'étonnerait. Mais comme je te dis, là, je n'ai aucune idée, alors il faudrait que je voie le code.

n°315110
djok_fb
C'était mieux avant!
Posté le 21-02-2003 à 17:19:03  profilanswer
 

c'est plutot conséquent...
 

Code :
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import oracle.xml.parser.v2.*;
  5. import java.io.*;
  6. import java.util.*;
  7. import org.w3c.dom.*;
  8. public class CDebugFrame extends JFrame implements ActionListener,WindowListener,MouseListener
  9. {
  10.    protected XMLDocument               xd;
  11.    protected XMLDocument               xmlOutDoc;
  12.    protected XMLElement                xmlOut;
  13.  
  14.    protected FileInputStream           fd;
  15.    protected DOMParser                 parser;
  16.  
  17.    protected JList                     bodyL;
  18.    protected Vector                    bodyV;
  19.    protected JScrollPane               scrollList;
  20.  
  21.    protected JLabel                    nfoLabel;
  22.  
  23.    protected CEnvDisplay               envDisp;
  24.  
  25.    protected String                    fXML;
  26.  
  27.    protected FileOutputStream          outFile;
  28.  
  29.    protected String                    lastOpenPath;
  30.  
  31.    // Bouttons sud
  32.    private   JButton                   showXMLB;
  33.    private   JButton                   saveDB;
  34.    private   JButton                   saveOB;
  35.    private   JButton                   exitB;
  36.  
  37.    // Autre
  38.    protected JFrame                    parentF;
  39.  
  40.    public CDebugFrame(String titre, JFrame parent,String fichierXMLDebug,XMLElement xe)
  41.    {
  42.       super(titre);
  43.       parentF = parent;
  44.       xmlOut = xe;
  45.       lastOpenPath = null;
  46.       xmlOutDoc = new XMLDocument();
  47.       Node mNode = (Node)xmlOutDoc.createElement("SPOT_Production_Orders" );
  48.       mNode.appendChild(xe.cloneNode(true));
  49.       xmlOutDoc.appendChild(mNode.cloneNode(true));
  50.       xmlOutDoc.setEncoding("UTF-8" );
  51.       xmlOutDoc.setVersion("1.0" );
  52.       fXML = fichierXMLDebug;
  53.       try
  54.       {
  55.          outFile = new FileOutputStream("result.xml" );
  56.          xmlOutDoc.print(outFile);
  57.          outFile.close();
  58.       }
  59.       catch(Exception eX)
  60.       {
  61.          System.out.println("Warning! Could not create XML Result File." );
  62.          CWarningDlg g = new CWarningDlg(this,"Simulator message","Could not create XML Result File." );
  63.       }
  64.      
  65.       try
  66.       {
  67.          parser = new DOMParser();
  68.          fd = new FileInputStream(fichierXMLDebug);
  69.          parser.parse(fd);
  70.          xd = parser.getDocument();
  71.       }
  72.       catch (Exception e)
  73.       {
  74.          System.out.println("Warning! Could not open XML Debug File." );
  75.          CWarningDlg g = new CWarningDlg(this,"Simulator message","Could not open XML Debug File." );
  76.       }
  77.       CEnvDisplay envDisp = new CEnvDisplay("Used vars",xd);
  78.       init();
  79.       this.show();
  80.       parent.setEnabled(false);
  81.       envDisp.show();
  82.    }
  83.  
  84.    public void mouseClicked(MouseEvent e)
  85.    {
  86.       if (!(bodyL.isSelectionEmpty()))
  87.       {
  88.          int index = bodyL.getSelectedIndex();
  89.          envDisp.currentInstr=index;
  90.          envDisp.setMainListVector();
  91.       }
  92.    }
  93.  
  94.    public void mouseEntered(MouseEvent e) {}
  95.    public void mouseExited(MouseEvent e) {}
  96.    public void mousePressed(MouseEvent e) {}
  97.    public void mouseReleased(MouseEvent e) {}
  98.  
  99.    public void init()
  100.    {
  101.       JPanel southP = new JPanel(new GridLayout(1,4));
  102.       if (xmlOut!=null)
  103.          nfoLabel = new JLabel("<html><p align=\"center\">Generated XML File OK</p></html>" );
  104.       else
  105.          nfoLabel = new JLabel("<html><p align=\"center\">Generated XML File KO</p></html>" );
  106.       this.setSize(800,480);
  107.       this.setLocation(10,96);
  108.       this.getContentPane().setLayout(new BorderLayout());
  109.       this.setResizable(true);
  110.      
  111.       // Mise en place des bouttons
  112.       showXMLB = new JButton("Show XML" );
  113.       showXMLB.addActionListener(this);
  114.       saveDB = new JButton("Save Debug Info" );
  115.       saveDB.addActionListener(this);
  116.       saveOB = new JButton("Save Generated XML" );
  117.       saveOB.addActionListener(this);
  118.       exitB = new JButton("Quit" );
  119.       exitB.addActionListener(this);
  120.      
  121.       // Ajout au panel Sud
  122.       southP.add(saveDB);
  123.       southP.add(saveOB);
  124.       southP.add(showXMLB);
  125.       southP.add(exitB);
  126.      
  127.       // Mise en place du corps principal
  128.       bodyL = new JList(bodyV = loadInfoFromDebugXML());
  129.       bodyL.addMouseListener(this);
  130.       scrollList = new JScrollPane(bodyL);
  131.       bodyL.setSelectedIndex(0);
  132.       bodyL.setVisibleRowCount(23);
  133.       // Ajout dans le main panel
  134.       this.getContentPane().add(nfoLabel,BorderLayout.NORTH);
  135.       this.getContentPane().add(scrollList,BorderLayout.CENTER);
  136.       this.getContentPane().add(southP,BorderLayout.SOUTH);
  137.    }
  138.  
  139.    public Vector loadInfoFromDebugXML()
  140.    {
  141.       Vector res = new Vector(10,10);
  142.       int i;
  143.       NodeList nl = xd.getElementsByTagName("currentInstruction" );
  144.       NodeList nlR = xd.getElementsByTagName("Results" );
  145.       for (i=0;i<nl.getLength();i++)
  146.          res.add("<HTML>" + nl.item(i).getFirstChild().getNodeValue() + "<font color=\"red\"> = " + nlR.item(i).getFirstChild().getNodeValue() + "</font></HTML>" );
  147.       System.out.println("->" + i);
  148.       return res;
  149.    }
  150.  
  151.    public void windowActivated(WindowEvent e) {}
  152.    public void windowClosed(WindowEvent e) {}
  153.    public void windowClosing(WindowEvent e) { parentF.setEnabled(true);this.dispose(); }
  154.    public void windowDeactivated(WindowEvent e) {}
  155.    public void windowDeiconified(WindowEvent e) {}
  156.    public void windowIconified(WindowEvent e) {}
  157.    public void windowOpened(WindowEvent e) {}
  158.  
  159.    public void actionPerformed(ActionEvent e)
  160.    {
  161.       if (e.getActionCommand().equals("Quit" ))
  162.       {
  163.          envDisp.dispose();
  164.          parentF.setEnabled(true);
  165.          this.dispose();
  166.       }
  167.       if (e.getActionCommand().equals("Save Debug Info" ))
  168.       {
  169.          JFileChooser cdataChoice;
  170.          if (lastOpenPath==null)
  171.             cdataChoice = new JFileChooser();
  172.          else
  173.             cdataChoice = new JFileChooser(lastOpenPath);
  174.          ExampleFileFilter filter = new ExampleFileFilter();
  175.          filter.addExtension("xml" );
  176.          filter.setDescription("XML Files" );
  177.          cdataChoice.setFileFilter(filter);
  178.          int choiceRet = cdataChoice.showSaveDialog(this);
  179.          if(choiceRet == JFileChooser.APPROVE_OPTION)
  180.          {
  181.             try
  182.             {
  183.                //sqlLabel.setText(cdataChoice.getSelectedFile().getAbsolutePath());
  184.                lastOpenPath = cdataChoice.getSelectedFile().getParent();
  185.                File fSour = new File(fXML);
  186.                File fDest = new File(cdataChoice.getSelectedFile().getAbsolutePath());
  187.                CommonClass.fileCopy(fSour,fDest);
  188.                System.out.println("Save as " + cdataChoice.getSelectedFile().getAbsolutePath() + " : Successful." );
  189.             }
  190.             catch(Exception exc)
  191.             {
  192.                System.out.println("Error while writing XML Debug file : " + exc);
  193.                CWarningDlg g = new CWarningDlg(this,"CData file saving","Error while saving XML Debug file." );
  194.             }
  195.          }
  196.       }
  197.      
  198.       if (e.getActionCommand().equals("Save Generated XML" ))
  199.       {
  200.          JFileChooser cdataChoice;
  201.          if (lastOpenPath==null)
  202.             cdataChoice = new JFileChooser();
  203.          else
  204.             cdataChoice = new JFileChooser(lastOpenPath);
  205.          ExampleFileFilter filter = new ExampleFileFilter();
  206.          filter.addExtension("xml" );
  207.          filter.addExtension("ord" );
  208.          filter.setDescription("XML Files" );
  209.          cdataChoice.setFileFilter(filter);
  210.          int choiceRet = cdataChoice.showSaveDialog(this);
  211.          if(choiceRet == JFileChooser.APPROVE_OPTION)
  212.          {
  213.             try
  214.             {
  215.                //sqlLabel.setText(cdataChoice.getSelectedFile().getAbsolutePath());
  216.                lastOpenPath = cdataChoice.getSelectedFile().getParent();
  217.                File fSour = new File("result.xml" );
  218.                File fDest = new File(cdataChoice.getSelectedFile().getAbsolutePath());
  219.                CommonClass.fileCopy(fSour,fDest);
  220.                System.out.println("Save as " + cdataChoice.getSelectedFile().getAbsolutePath() + " : Successful." );
  221.             }
  222.             catch(Exception exc)
  223.             {
  224.                System.out.println("Error while writing XML Result file : " + exc);
  225.                CWarningDlg g = new CWarningDlg(this,"CData file saving","Error while saving XML Result file." );
  226.             }
  227.          }
  228.       }
  229.      
  230.       if (e.getActionCommand().equals("Show XML" ))
  231.       {
  232.          try
  233.          {
  234.             Runtime.getRuntime().exec("cmd /c result.xml" );
  235.          }
  236.          catch(Exception eRT)
  237.          {
  238.             System.out.println("Cannot show XML File" );
  239.             CWarningDlg g = new CWarningDlg(this,"Simulator message","Could not open XML file." );
  240.          }
  241.       }
  242.    } 
  243. }


 
mais le voila...chuis plutot perturbé car en 5 ans, ca me l'a jamais fait

n°315112
djok_fb
C'était mieux avant!
Posté le 21-02-2003 à 17:21:45  profilanswer
 

j'ai déplacé le bloc mouselistener au cas ou j'aurais mis des {} bidons non détecté par le compilo...mais ca a rien changer...
 
je parle de la quantité de threads car j'ai déjà eu un pb de ce genre sur une machine ou je n'ai le droit qu'a 5 threads (hyper bizarre)...
sachant que chaque frame prend 1 thread...j'ai pensé a ca

n°315140
BifaceMcLe​OD
The HighGlandeur
Posté le 21-02-2003 à 18:04:43  profilanswer
 

Là, je sèche.  :( L'étape suivante, c'est le passage au débogueur, mais ça va être serré.

n°315663
darklord
You're welcome
Posté le 22-02-2003 à 21:35:34  profilanswer
 

ajoute un
 

Citation :


if (body == null)
    System.out.println("Body est null !!!" );


 
au début de ta méthode mouseClicked


---------------
Just because you feel good does not make you right
mood
Publicité
Posté le 22-02-2003 à 21:35:34  profilanswer
 

n°316435
djok_fb
C'était mieux avant!
Posté le 24-02-2003 à 13:24:05  profilanswer
 

dsl DarkLord, mais ca affiche rien...

n°316460
djok_fb
C'était mieux avant!
Posté le 24-02-2003 à 13:45:01  profilanswer
 

Code :
  1. public void mouseClicked(MouseEvent e)
  2.        {
  3.             if (!(bodyL.isSelectionEmpty()))
  4.             {
  5.                  int index = bodyL.getSelectedIndex();
  6.                  envDisp.currentInstr=index;
  7.                  envDisp.setMainListVector();
  8.             }
  9.        }


 
j'ai trouvé, le problème vient de envDisp mais le truc du nullPointer n'indique pas la bonne ligne...
 
la variable envDisp etait redeclaré dans le constructeur alors que c'est un champ de la classe...
 
merci de votre aide...

n°316564
BifaceMcLe​OD
The HighGlandeur
Posté le 24-02-2003 à 15:04:29  profilanswer
 

D'où l'utilité de toujours accéder aux attributs (et méthodes) de la classe en les préfixant par "this." ...

n°316577
djok_fb
C'était mieux avant!
Posté le 24-02-2003 à 15:13:56  profilanswer
 

yep...
 
désolé pour le dérangement...
 
merci a vous


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  [Java] Bizarerie du MouseListener

 

Sujets relatifs
[JAVA] - Tester la non nullité d'un champ - Besoin Aide 1 min maxi ![java]Ouvrir une popup html depuis le bouton de mon applet??
un RAD gratuit pour developper an JAVA?[java] qui utilisent eclipse ?!
[JAVA] - Projet d'orienté Objet - Problème clair & détaillé - BloquéAller chercehr une image sur le net, à partir d'un prog en JAVA
Transformer un programme JAVA en fichier .EXE[java]créer une tempo, c'est possible??
[Java] traduction d' algopourquoi je vois pas les applet java sur mon poste
Plus de sujets relatifs à : [Java] Bizarerie du MouseListener


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR