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

Agents de placement/Fenêtres Java Discussion :

getcontentpane() JFrame remplacer par quoi?


Sujet :

Agents de placement/Fenêtres Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Décembre 2012
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Décembre 2012
    Messages : 16
    Points : 15
    Points
    15
    Par défaut getcontentpane() JFrame remplacer par quoi?
    Bonjour ,
    Voila mon code :
    Code java : 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
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    package javatool;
     
    import com.sun.comm.Win32Driver;
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    import javax.swing.*;
     
     
    public class JavaSerialPort extends Thread implements Runnable,SerialPortEventListener {
     
            /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
     
        // Variables declaration - do not modify
        private javax.swing.JComboBox PortList;
        private javax.swing.JToggleButton StartCapture;
        private javax.swing.JTextField Traffic;
        private javax.swing.JFrame JFrame;
        private javax.swing.GroupLayout Layout;
        private CommPortIdentifier portId;
        private SerialPort serialPort;
        private BufferedReader fluxLecture;
        private boolean running;
        Thread readthread;
        InputStream inputstream;
        static String Port;
     
         // End of variables declaration
    	/**
             * Constructeur qui récupère l'identifiant du port et lance l'ouverture.
             */
    	public JavaSerialPort(String port ) {
                     initComponents();
    		//initialisation du driver
    		Win32Driver w32Driver = new Win32Driver();
    		w32Driver.initialize();
    		//récupération de l'identifiant du port
    		try {
    			portId = CommPortIdentifier.getPortIdentifier(port);
    		} catch (NoSuchPortException e) {
    		}
     
    		//ouverture du port
    		try {
    			serialPort = (SerialPort) portId.open("Micropixel", 2000);
    		} catch (PortInUseException e) {
    		}
    		//récupération du flux
    		try {
    			inputstream = serialPort.getInputStream();
    		} catch (IOException e) {
    		}
    		//ajout du listener
    		try {
    			serialPort.addEventListener(this);
    		} catch (TooManyListenersException e) {
    		}
    		//paramétrage du port
    		serialPort.notifyOnDataAvailable(true);
    		try {   
    			serialPort.setSerialPortParams(
    				serialPort.getBaudRate(),
    				serialPort.getDataBits(),
    				serialPort. getStopBits(),
    				serialPort.getParity());
    		} catch (UnsupportedCommOperationException e) {
    		}
    		System.out.println("port ouvert, attente de lecture");
    	}
     
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents  () {
     
            PortList = new javax.swing.JComboBox();
            StartCapture = new javax.swing.JToggleButton();
            Traffic = new javax.swing.JTextField();
            JFrame = new javax.swing.JFrame();
            JFrame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            JFrame.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
     
            PortList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "COM1", "COM2" }));
            PortList.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    PortListActionPerformed(evt);
                }
            });
     
            StartCapture.setText("Start Capture");
            StartCapture.setToolTipText("");
     
            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(46, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(StartCapture)
                            .addGap(95, 95, 95))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(PortList, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(Traffic, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(38, 38, 38))))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(122, 122, 122)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(PortList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(Traffic, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(88, 88, 88)
                    .addComponent(StartCapture)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            PortList.setSelectedIndex(0);
     
            pack();
     
        }// </editor-fold>
     
        private void PortListActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            String SI ; 
                   SI = (String)PortList.getSelectedItem();
                   Port = SI;
        }
    public void TrafficShow (String S)
    {
     
    }
        /**
         * @param args the command line arguments
         */
     
     
    	public void run() {
    		running = true;
    		while (running) {
    			try {
    				Thread.sleep(2000);
    			} catch (InterruptedException e) {
    			}
    		}
    		//fermeture du flux et port
    		try {
    			inputstream.close();
    		} catch (IOException e) {
    		}
    		serialPort.close();
    	}
    	/**
             * Méthode de gestion des événements.
             */
    	public void serialEvent(SerialPortEvent event) {
    		//gestion des événements sur le port :
    		//on ne fait rien sauf quand les données sont disponibles
    		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 nymBytes = inputstream.read(readbuffer);
                                    }
                                    System.out.printf(new String(readbuffer));
                                }catch (IOException e) {System.out.println(e);}
     
     
    				break;
    		}
    	}
    	/*
    	 * Permet l'arrêt du thread
    	 */
    	public void stopThread() {
     
    		running = false;
    	}
    	/**
             * Méthode principale de l'exemple.
             */
    	public static void main(String[] args) {
    		//Récuperation du port en argument
                 java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new TrafficSerialPort().setVisible(true);}});
     
     
    		//lancement de l'appli
    		JavaSerialPort modeEve=new JavaSerialPort(Port);
    		modeEve.start();
    		//"interface utilisateur"
    		System.out.println("taper q pour quitter");
    		//construction flux lecture
    		BufferedReader clavier =
    			new BufferedReader(new InputStreamReader(System.in));
    		//lecture sur le flux entrée.
    		try {
    			String lu = clavier.readLine();
    			while (!lu.equals("q")) {
    			}
    		} catch (IOException e) {
    		}
    		modeEve.stopThread();
    	}
    }

    la methode getcontentpane() n'est pas reconnu car j'ai pas mis extends javax.swing.JFrame et je peux pas le faire car j'ai Thread qui est necessaire pour mon programme.
    Qu'est ce que je peux faire SVP ?

  2. #2
    Candidat au Club
    Homme Profil pro
    Architecte technique
    Inscrit en
    Décembre 2012
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Architecte technique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2012
    Messages : 1
    Points : 2
    Points
    2
    Par défaut
    Bonjour,

    Si tu veux faire des Thread tu peux soit étendre Thread soit implémenter Runnable. Là tu fais les deux, c'est inutile.

    Si tu implémente Runnable, tu auras juste a mettre ton objet dans le constructeur de Thread comme ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    JavaSerialPort maClasse = new JavaSerialPort();
    Thread thread = new Thread(maClasse);
    thread.start();
    Du coup, tu n'as pas besoin d'étendre Thread, et sa te libère la place pour JFrame.

  3. #3
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Bah, il faut que tu ajoutes les nom de l'objet en question devant.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    JFrame.getContentPane()
    Et puis suivre les conventions de nommage java si possible, c'est à dire de faire en sorte que tes noms de variables/attributs/méthodes commencent par des minuscules pour ne pas être confondues avec des noms de classes
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  4. #4
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Décembre 2012
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Décembre 2012
    Messages : 16
    Points : 15
    Points
    15
    Par défaut
    merci pour la réponse et ta solution a été avec succés mais dans main la méthode start() n'est pas reconnu :

    merci encore
    un seul probleme n'est pas résolu
    la méthode pack() maintenant n'est pas reconnu

  5. #5
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Bah, pour le pack, ce ne serait pas absolument le même problème que pour le getContentPane?

    Avant de faire du GUI avec Swing, il serait peut être un peu intelligent d'apprendre java... Genre, des notions d'objet de base...
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  6. #6
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Décembre 2012
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Décembre 2012
    Messages : 16
    Points : 15
    Points
    15
    Par défaut
    bon vous avez raison je suis en train d'apprendre et avancer dans mon programme donc s'il te plait si ta le lien pour apprendre sur mon probleme dis le moi.

  7. #7
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Décembre 2012
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Décembre 2012
    Messages : 16
    Points : 15
    Points
    15
    Par défaut
    ok je vais marquer cette discussion merci pour tous pour votre aide .
    pack() est une methode de javax.swing.JFrame alors :
    JFrame.pack() ;

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

Discussions similaires

  1. Réponses: 2
    Dernier message: 15/11/2011, 14h55
  2. Réponses: 1
    Dernier message: 05/06/2006, 17h27
  3. Par quoi remplacer le mot Démarrer?
    Par sourivore dans le forum Autres Logiciels
    Réponses: 5
    Dernier message: 08/03/2006, 14h08
  4. [Choix] Par quoi je remplace le CMS phpnuke ?
    Par nouna dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 12
    Dernier message: 15/02/2006, 12h35
  5. Réponses: 2
    Dernier message: 16/01/2006, 22h59

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