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

Java Discussion :

Lien entre deux classe


Sujet :

Java

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut Lien entre deux classe
    Bonjour, je suis occupé de faire un programme sous NetBeans et j'ai 2 fichier l'un pour mon interface graphique l'autre pour me connecter à mon port com et attendre que des données arrivent. Le problème est que lorsque je lance mon projet (les 2 fichiers sont dans le meme block) seul mon interface graphique se lance. Il doit exister un moment pour exécuter les 2 en meme temps en mettant une ligne dans mon programme main(interface) non?

    Voici mes 2 fichier :

    Main : (interface graphique)
    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
    107
    108
     
    package blackbox;
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
     
    public class Main extends javax.swing.JFrame
    {
        static CommPortIdentifier portId;
        static Enumeration          portList;
     
        public Main()
        {
            initComponents();
        }
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
     
            jComboBox1 = new javax.swing.JComboBox();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jButton1.setText("Test Connection");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            jButton2.setText("Lister les Ports");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
     
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jScrollPane1.setViewportView(jTextArea1);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGap(18, 18, 18)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton2)
                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton1)))
                    .addContainerGap())
            );
     
            pack();
        }// </editor-fold>                       
     
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
     
    }                                       
     
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements())
        {
            portId = (CommPortIdentifier) portList.nextElement();
            jComboBox1.addItem(portId.getName());
        }
    }                                       
        public static void main(String args[])
        {
            java.awt.EventQueue.invokeLater(new Runnable()
            {
                public void run()
                {
                    new Main().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify                    
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea jTextArea1;
        // End of variables declaration
    }
    Read : (connection port com et attente données)
    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
    107
    108
    109
    110
     
    package blackbox;
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
     
    public class Read implements Runnable, SerialPortEventListener {
        static CommPortIdentifier portId;
        static Enumeration          portList;
        InputStream              inputStream;
        SerialPort              serialPort;
        Thread              readThread;
     
        public static void main(String[] args) {
        boolean              portFound = false;
        String              defaultPort = "/dev/ttyS0";
     
         if (args.length > 0) {
            defaultPort = args[0];
        }
     
        portList = CommPortIdentifier.getPortIdentifiers();
     
        while (portList.hasMoreElements()) {
            portId = (CommPortIdentifier) portList.nextElement();
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            if (portId.getName().equals(defaultPort)) {
                System.out.println("Found port: "+defaultPort);
                portFound = true;
                Read reader = new Read();
            }
            }
        }
        if (!portFound) {
            System.out.println("port " + defaultPort + " not found.");
        }
     
        }
     
        public Read() {
        try {
            serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
        } catch (PortInUseException e) {}
     
        try {
            inputStream = serialPort.getInputStream();
        } catch (IOException e) {}
     
        try {
            serialPort.addEventListener(this);
        } catch (TooManyListenersException e) {}
     
        serialPort.notifyOnDataAvailable(true);
     
        try {
            serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
                           SerialPort.STOPBITS_1,
                           SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {}
     
        readThread = new Thread(this);
     
        readThread.start();
        }
     
        public void run() {
        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {}
        }
     
        public void serialEvent(SerialPortEvent event) {
        switch (event.getEventType()) {
     
        case SerialPortEvent.BI:
     
        case SerialPortEvent.OE:
     
        case SerialPortEvent.FE:
     
        case SerialPortEvent.PE:
     
        case SerialPortEvent.CD:
     
        case SerialPortEvent.CTS:
     
        case SerialPortEvent.DSR:
     
        case SerialPortEvent.RI:
     
        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;
     
        case SerialPortEvent.DATA_AVAILABLE:
     
            byte[] readBuffer = new byte[20];
            try {
            while (inputStream.available() > 0)
                    {
                        int numBytes = inputStream.read(readBuffer);
            }
     
            System.out.print(new String(readBuffer));
            } catch (IOException e) {}
     
            break;
        }
        }
     
    }
    merci d'avance

  2. #2
    Membre émérite
    Avatar de gifffftane
    Profil pro
    Inscrit en
    Février 2007
    Messages
    2 354
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire (Rhône Alpes)

    Informations forums :
    Inscription : Février 2007
    Messages : 2 354
    Points : 2 582
    Points
    2 582
    Par défaut
    Oui, il faut que tu décides laquelle des deux classes sera la principale.

    Dans cette classe, tu devras écrire le code qui lancera l'autre et procéder au contrôle de cette autre.

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    Ok daccord, c'est bien ce qu'il me semblait.

    Alors ma classe principale sera Main et Read la suivante comment je fait pour que Read s'exécute lorsque je clique sur un boutton?


    Merci de votre aide

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    je fait comment pour lancer la 2eme quand je clique sur un boutton de la première svp
    merci

  5. #5
    Membre éclairé

    Étudiant
    Inscrit en
    Octobre 2007
    Messages
    510
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2007
    Messages : 510
    Points : 803
    Points
    803
    Par défaut
    bonjour

    parfait alors deux choses :

    si ta classe main est la pricipale alors ta méthode main doit s'y trouver.

    ensoite pour lancer ta deuxieme classe lorsque qu'il y a appuie sur le bouton de l'interface il te suffit de faire ca :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    JButton.addActionListener(new ActionListener() {
     
            public void actionPerformed(ActionEvent e) {
                    new Read()
            }
    });

  6. #6
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    Slt, merci pour ta réponse voila ce que j'ai ajouté :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        new Read();
    }
    mais lorsque je lance mon main et que je clique sur mon boutton voici ce qu'il s'affiche :

    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
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
            at blackbox.Read.<init>(Read.java:51)
            at blackbox.Main.jButton1ActionPerformed(Main.java:106)
            at blackbox.Main.access$000(Main.java:6)
            at blackbox.Main$1.actionPerformed(Main.java:35)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6041)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
            at java.awt.Component.processEvent(Component.java:5806)
            at java.awt.Container.processEvent(Container.java:2058)
            at java.awt.Component.dispatchEventImpl(Component.java:4413)
            at java.awt.Container.dispatchEventImpl(Container.java:2116)
            at java.awt.Component.dispatchEvent(Component.java:4243)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
            at java.awt.Container.dispatchEventImpl(Container.java:2102)
            at java.awt.Window.dispatchEventImpl(Window.java:2440)
            at java.awt.Component.dispatchEvent(Component.java:4243)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    Donc ca marche pas et je sais pas pourquoi

    merci de votre aide

  7. #7
    Membre chevronné
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Points : 2 197
    Points
    2 197
    Par défaut
    Il y a un objet null à la ligne 51 de ta classe Read.

    Si tu donnes le code de la classe on pourra t'aider, j'espère qu'il a changé depuis le 1er post car sinon tu ne gère même pas les exceptions...

  8. #8
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    mon read n'a pas changer car je ne vois pas pourquoi je devrai gérer les exeption.

    Sinon en ligne 51 j'ai ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
    le code au alentour est :
    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
    public Read()
        {
            try
            {
                serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
                System.out.println(portId);
     
     
    	}
            catch (PortInUseException e) {}
     
    	try
            {
    	    inputStream = serialPort.getInputStream();
    	}
            catch (IOException e) {}
     
    	try
            {
    	    serialPort.addEventListener(this);
    	}
            catch (TooManyListenersException e) {}
     
    	serialPort.notifyOnDataAvailable(true);
     
    	try
            {
    	    serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
    	}
            catch (UnsupportedCommOperationException e) {}
     
    	readThread = new Thread(this);
     
    	readThread.start();
        }
    et dans les exeption je met quoi en fait si je doit en faire? des

    println("erreur ...");

    Merci à vous

  9. #9
    Membre éclairé

    Étudiant
    Inscrit en
    Octobre 2007
    Messages
    510
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2007
    Messages : 510
    Points : 803
    Points
    803
    Par défaut
    ca serai bien que tu signale ou est la ligne 51 vu que c'est celle qui fait péter une exception. Ca éviteras a chacun de perdre du temps. PS: gérer les exceptions permet bien souvent d'éviter des erreurs qui passe parfois a l'as.

  10. #10
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    ligne 51 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
    Ok pour gérer les exeption mais que doit je mettre exactement?

    Merci de votre aide en tout cas

  11. #11
    Membre chevronné
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Points : 2 197
    Points
    2 197
    Par défaut
    C'est portId qui est null, je pense que la liste des identifiants de ports était vide dans ta méthode main.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    try
            {
                serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
                System.out.println(portId);
     
     
    	}
            catch (PortInUseException e) {}
     
    	try
            {
    	    inputStream = serialPort.getInputStream();
    	}
            catch (IOException e) {}
    Ca ne te choque pas que si tu as une exception lors de l'ouverture du port COM, parce qu'il est déja utilisé, tu essais quand même de créer un flux dessus?
    Les exceptions ne sont pas faites uniquement pour faire un print, c'est surtout fait pour ne pas exécuter du code si on a eu une erreur précédemment.

    Pour faire simple, mets tout ton code dans un seul try et ensuite les catchs. N'est-ce pas plus clair? :
    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
    public Read() {
            try {
                serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
                System.out.println(portId);
                inputStream = serialPort.getInputStream();
                serialPort.addEventListener(this);
                serialPort.notifyOnDataAvailable(true);
                serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
     
                readThread = new Thread(this);
                readThread.start();
            }
            catch (PortInUseException e) {
            }
            catch (IOException e) {
            }
            catch (TooManyListenersException e) {
            }
            catch (UnsupportedCommOperationException e) {
            }        
        }

  12. #12
    Membre éclairé

    Étudiant
    Inscrit en
    Octobre 2007
    Messages
    510
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2007
    Messages : 510
    Points : 803
    Points
    803
    Par défaut
    le but de ce try catch est simplement de ne pas executer le code entre les deux instrutions si l'une des exceptions est levée... cela évite d'avoir des conflits et de risquer une erreur bête qui puisse te faire planter ton appli

  13. #13
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    ok merci j'ai donc changer mon code de mon Read voici ce qu'il est devenu :

    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
    public Read()
        {
            portList = CommPortIdentifier.getPortIdentifiers();
            while (portList.hasMoreElements()) 
            {
                portId = (CommPortIdentifier) portList.nextElement();
            }
     
            try
            {
                serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
                System.out.println(portId);
                inputStream = serialPort.getInputStream();
                serialPort.addEventListener(this);
                serialPort.notifyOnDataAvailable(true);
                serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
     
                readThread = new Thread(this);
                readThread.start();
            }
            catch (PortInUseException e)
            {
            }
            catch (IOException e)
            {
            }
            catch (TooManyListenersException e)
            {
            }
            catch (UnsupportedCommOperationException e)
            {
            }
    et voici mon erreur maintenant :

    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
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com.sun.comm.LinuxParallel cannot be cast to javax.comm.SerialPort
            at blackbox.Read.<init>(Read.java:57)
            at blackbox.Main.jButton1ActionPerformed(Main.java:106)
            at blackbox.Main.access$000(Main.java:6)
            at blackbox.Main$1.actionPerformed(Main.java:35)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6041)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
            at java.awt.Component.processEvent(Component.java:5806)
            at java.awt.Container.processEvent(Container.java:2058)
            at java.awt.Component.dispatchEventImpl(Component.java:4413)
            at java.awt.Container.dispatchEventImpl(Container.java:2116)
            at java.awt.Component.dispatchEvent(Component.java:4243)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
            at java.awt.Container.dispatchEventImpl(Container.java:2102)
            at java.awt.Window.dispatchEventImpl(Window.java:2440)
            at java.awt.Component.dispatchEvent(Component.java:4243)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    Merci pour l'explication de l'exeption

  14. #14
    Membre chevronné
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Points : 2 197
    Points
    2 197
    Par défaut
    Où est passé le test que tu faisais précédemment pour savoir si il s'agissait d'un port série? là tu essais de caster un port parallèle en port série, ta boucle ne fait aucun controle, elle ne sert à rien.

  15. #15
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    je vien de me rendre compte que c'était nimp ce bout de code j'en refait un je test et je vous tien au courant

    Merci

  16. #16
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    me revoila
    avec de bonne nouvelle j'ai réussi et cela grace à vous merci bien.

    Voici donc le bout de code permettant que lorsque j'appui sur une touche on attend de recevoir les données d'un autre pc et les affiches ela fonctionne bien.

    Merci à vous

    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
    public Read()
        {
            boolean		      portFound = false;
            String		      defaultPort = "/dev/ttyS0";
            portList = CommPortIdentifier.getPortIdentifiers();
    	while (portList.hasMoreElements())
            {
    	    portId = (CommPortIdentifier) portList.nextElement();
    	    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
                {
     
     
                    if (portId.getName().equals(defaultPort))
                    {
    		    System.out.println("Found port: "+defaultPort);
    		    portFound = true;
            try
            {
                serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
                System.out.println(portId);
                inputStream = serialPort.getInputStream();
                serialPort.addEventListener(this);
                serialPort.notifyOnDataAvailable(true);
                serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
     
                readThread = new Thread(this);
                readThread.start();
            }
            catch (PortInUseException e)
            {
            }
            catch (IOException e)
            {
            }
            catch (TooManyListenersException e)
            {
            }
            catch (UnsupportedCommOperationException e)
            {
            }
     
     
     
                        		} 
    	    } 
    	}
        }
    Encore merci de votre aide
    Vous êtes vraiment sympa de m'avoir aider et en plus vous m'avait appris plein de chose.

    Continuer comme ca encore merci à vous

  17. #17
    Membre chevronné
    Avatar de CheryBen
    Inscrit en
    Mai 2005
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 599
    Points : 2 197
    Points
    2 197
    Par défaut
    De rien

    Pense au bouton

  18. #18
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    tu dit de rien mais bon c'est super sympa d'avoir pris le temps de m'aider. Car j'avais poster ce message sur un autre forum avant et personnes ne ma encore répondu à ce jour.

    Alors je pense que je vais rester ici car c'est conviviale et plein de personne sont la il y a de bon tuto aussi j'ai pas tout fait encore lol qui sait un jour peut etre je pourrais aider moi aussi les autres.

    Merci à vous

  19. #19
    Membre éclairé

    Étudiant
    Inscrit en
    Octobre 2007
    Messages
    510
    Détails du profil
    Informations personnelles :
    Âge : 38

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2007
    Messages : 510
    Points : 803
    Points
    803
    Par défaut
    mais de rien c'est le but de ce forum; aujourd'hui c'est toi qui pose des questions et dans trois mois tu commence a répondre (dans 6 tu passe tout ton temps sur le chat ) bonne chance pour la suite

  20. #20
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 82
    Points : 35
    Points
    35
    Par défaut
    Merci bien bonne continuation à tous aussi

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 12
    Dernier message: 19/04/2008, 16h19
  2. lien entre deux sous formulaire :(
    Par souska dans le forum Access
    Réponses: 4
    Dernier message: 20/09/2005, 21h37
  3. Réponses: 5
    Dernier message: 17/08/2005, 12h40
  4. Type de lien entre deux associations
    Par thibal dans le forum PowerAMC
    Réponses: 2
    Dernier message: 17/06/2005, 16h53
  5. [VB.NET] ComboBox lien entre deux tables
    Par VDB1 dans le forum Windows Forms
    Réponses: 3
    Dernier message: 15/07/2004, 12h15

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