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

NetBeans Java Discussion :

Lien entre 2 fichiers Java


Sujet :

NetBeans 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 2 fichiers Java
    Bonjour,

    dans mon porjet j'ai 2 fichier java, l'un pour l'interface graphique l'autre pour me connecter via mon port com.

    Le second fichier me permet l'énumération des différents port présent sur mon PC. J'aimerais que cela s'affiche sur mon interface graphique dans une combobox.

    Comment puis je faire???

    Merci de votre aide

  2. #2
    Membre éprouvé Avatar de anisj1m
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2006
    Messages
    1 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 067
    Points : 955
    Points
    955
    Par défaut
    instanciation du deuxieme classe dans la premiere et recuperation des donnees via une fonction que tu doit la definir dans la deuxieme classe et enfin affecte ces donnees a ton comboBox.

  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
    waou j'ai pas tout compris tu peut m'expliquer en détail
    je suis novice sur le sujet

    merci a toi en tout cas déja

  4. #4
    Membre éprouvé Avatar de anisj1m
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2006
    Messages
    1 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 067
    Points : 955
    Points
    955
    Par défaut
    par example si la premier classe est A.java et la deuxieme est B.java:
    por l'instaciation du mettra dans la methode qui tu vas utiliser:
    public A a = new A();

    pour la recuperation des données, il faut créé une methode du meme type que le type que tu vas recupéré lors de tes ports.

    dans la meme methode; ou tu as fait l'instanciation; tu doit utiliser un variable du type (celle du fonction créé precedement), affecte cette variable par le resultat retourner par la methode.
    et enfin un simple "set" por le Combobox

  5. #5
    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
    j'essai et je te tient au courant

    Merci à toi

  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
    ptit souci j'ai fait ca :
    public gui Main = new gui();

    mon premier prog se nome Main et l'autre gui.

    J'ai donc fait ce que tu m'a dit c'est ce que j'ai mis précedement mais il me met une erreur

    Pourquoi?

  7. #7
    Membre éprouvé Avatar de anisj1m
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2006
    Messages
    1 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 067
    Points : 955
    Points
    955
    Par défaut
    est ce que tu peux nous copier vos fichier? ca sera trés facile ainsi.

    et n'oublier pas d'utiliser la balise code.

  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
    yes pas de souci:
    (j'ai enlevé ce que tu ma donné) pour mieu y voir)
    Prog : interface graphique c'est dans jcombobox16 que je veut affiché
    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
    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
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
     
    package celsiusconverterproject;
     
    public class CelsiusConverterGUI extends javax.swing.JFrame {
     
     
     
        public CelsiusConverterGUI() {
            initComponents();
            jTextArea1.append("Hello\n");
            for(int j=1;j<=10;j++)
            {
                jComboBox1.addItem(+j);
            }
     
        }
     
     
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            tempTextField1 = new javax.swing.JTextField();
            celsiusLabel = new javax.swing.JLabel();
            convertButton1 = new javax.swing.JButton();
            fahrenheitLabel2 = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            jTabbedPane1 = new javax.swing.JTabbedPane();
            jPanel1 = new javax.swing.JPanel();
            jComboBox1 = new javax.swing.JComboBox();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jComboBox2 = new javax.swing.JComboBox();
            jComboBox3 = new javax.swing.JComboBox();
            jLabel5 = new javax.swing.JLabel();
            jComboBox4 = new javax.swing.JComboBox();
            jPanel2 = new javax.swing.JPanel();
            jLabel6 = new javax.swing.JLabel();
            jLabel7 = new javax.swing.JLabel();
            jLabel8 = new javax.swing.JLabel();
            jLabel9 = new javax.swing.JLabel();
            jComboBox5 = new javax.swing.JComboBox();
            jComboBox6 = new javax.swing.JComboBox();
            jComboBox7 = new javax.swing.JComboBox();
            jComboBox8 = new javax.swing.JComboBox();
            jLabel10 = new javax.swing.JLabel();
            jComboBox9 = new javax.swing.JComboBox();
            jLabel11 = new javax.swing.JLabel();
            jComboBox10 = new javax.swing.JComboBox();
            jPanel3 = new javax.swing.JPanel();
            jLabel12 = new javax.swing.JLabel();
            jComboBox11 = new javax.swing.JComboBox();
            jLabel13 = new javax.swing.JLabel();
            jComboBox12 = new javax.swing.JComboBox();
            jLabel14 = new javax.swing.JLabel();
            jComboBox13 = new javax.swing.JComboBox();
            jLabel15 = new javax.swing.JLabel();
            jComboBox14 = new javax.swing.JComboBox();
            jLabel16 = new javax.swing.JLabel();
            jComboBox15 = new javax.swing.JComboBox();
            jButton1 = new javax.swing.JButton();
            jComboBox16 = new javax.swing.JComboBox();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("°C -> °F");
     
            tempTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    tempTextField1ActionPerformed(evt);
                }
            });
     
            celsiusLabel.setText("Celsius");
     
            convertButton1.setText("Conversion");
            convertButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    convertButton1ActionPerformed(evt);
                }
            });
     
            fahrenheitLabel2.setText("Fahrenheit");
     
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jScrollPane1.setViewportView(jTextArea1);
     
            jLabel2.setText("Débit de transmission (S201 = 38.4KBits/s) :");
     
            jLabel3.setText("Sous-Bande de fréquence (S206 = 868-868.6MHz) :");
     
            jLabel4.setText("Puissance de sortie (S202 = 25, 8 ou 3mW selon la Sous-Bande) :");
     
            jLabel5.setText("Canal Radio (S200 = 0) :");
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4)
                        .addComponent(jLabel2)
                        .addComponent(jLabel5))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(17, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel4)
                        .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel5)
                        .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(90, Short.MAX_VALUE))
            );
     
            jTabbedPane1.addTab("Liaison Radio (S20X)", jPanel1);
     
            jLabel6.setText("Vitesse série (S210 = 19200Bits/s) :");
     
            jLabel7.setText("Bits de parité (S212 = None) :");
     
            jLabel8.setText("Nombres de bits stop (S213 = 1) :");
     
            jLabel9.setText("Time-out de 2 à 100ms (S214 = 5) :");
     
            jLabel10.setText("Type de liaison série (S215 = RS232) :");
     
            jLabel11.setText("Contrôle de flux (S216 = None) :");
     
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel6)
                        .addComponent(jLabel10)
                        .addComponent(jLabel7)
                        .addComponent(jLabel8)
                        .addComponent(jLabel9)
                        .addComponent(jLabel11))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jComboBox10, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox8, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox7, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox9, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(188, Short.MAX_VALUE))
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel6)
                        .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel7)
                        .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(17, 17, 17)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel8)
                        .addComponent(jComboBox7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel9)
                        .addComponent(jComboBox8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel10)
                        .addComponent(jComboBox9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel11)
                        .addComponent(jComboBox10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            jTabbedPane1.addTab("Liaison Série (S21X)", jPanel2);
     
            jLabel12.setText("Mode de fonctionnement (S220 = Transparent) :");
     
            jLabel13.setText("Nombres d'itérations de 0 à 255 (S223 = 2) :");
     
            jLabel14.setText("LBT (S226 = OFF) :");
     
            jLabel15.setText("Temps d'attente aléatoir (S227 = OFF) :");
     
            jLabel16.setText("Mise en veille (S240 = No Low Power) :");
     
            javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
            jPanel3.setLayout(jPanel3Layout);
            jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel12)
                        .addComponent(jLabel13)
                        .addComponent(jLabel14)
                        .addComponent(jLabel15)
                        .addComponent(jLabel16))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jComboBox15, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox14, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jComboBox13, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox12, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBox11, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(125, Short.MAX_VALUE))
            );
            jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel12)
                        .addComponent(jComboBox11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel13)
                        .addComponent(jComboBox12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel14)
                        .addComponent(jComboBox13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jComboBox14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel15))
                    .addGap(15, 15, 15)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jComboBox15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel16))
                    .addGap(162, 162, 162))
            );
     
            jTabbedPane1.addTab("Mode (S22X & S24X)", jPanel3);
     
            jButton1.setText("Liste les Ports");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            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.LEADING)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 585, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(tempTextField1)
                                .addComponent(convertButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(celsiusLabel)
                                .addComponent(fahrenheitLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jComboBox16, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(27, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(celsiusLabel)
                                .addComponent(tempTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(convertButton1)
                                .addComponent(fahrenheitLabel2)))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButton1)
                        .addComponent(jComboBox16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(86, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>                        
     
    private void tempTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                               
    // TODO add your handling code here:
    }                                              
     
    private void convertButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                               
        //Parse degrees Celsius as a double and convert to Fahrenheit.
        float tempFahr = (float)((Double.parseDouble(tempTextField1.getText())) * 1.8 + 32);
        fahrenheitLabel2.setText(tempFahr + " Fahrenheit");
        jTextArea1.append("Réussi\n");
        jTextArea1.append(tempFahr + " Fahrenheit\n");
        //jTextArea1.append("jComboBox1");
        for(int i=1;i<=10;i++)
        {
            jTextArea1.append("Chiffre : "+i+"\n");
        }
        jComboBox1.addItem(tempFahr + " Fahrenheit");
        // TODO add your handling code here:
    }                                              
     
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        //(new SimpleRead()).setVisible(true);
        jComboBox16.getName(boum); 
    }                                        
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new CelsiusConverterGUI().setVisible(true);
     
                }
            });
        }
     
        // Variables declaration - do not modify                     
        private javax.swing.JLabel celsiusLabel;
        private javax.swing.JButton convertButton1;
        private javax.swing.JLabel fahrenheitLabel2;
        private javax.swing.JButton jButton1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JComboBox jComboBox10;
        private javax.swing.JComboBox jComboBox11;
        private javax.swing.JComboBox jComboBox12;
        private javax.swing.JComboBox jComboBox13;
        private javax.swing.JComboBox jComboBox14;
        private javax.swing.JComboBox jComboBox15;
        private javax.swing.JComboBox jComboBox16;
        private javax.swing.JComboBox jComboBox2;
        private javax.swing.JComboBox jComboBox3;
        private javax.swing.JComboBox jComboBox4;
        private javax.swing.JComboBox jComboBox5;
        private javax.swing.JComboBox jComboBox6;
        private javax.swing.JComboBox jComboBox7;
        private javax.swing.JComboBox jComboBox8;
        private javax.swing.JComboBox jComboBox9;
        private javax.swing.JLabel jLabel10;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel12;
        private javax.swing.JLabel jLabel13;
        private javax.swing.JLabel jLabel14;
        private javax.swing.JLabel jLabel15;
        private javax.swing.JLabel jLabel16;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTabbedPane jTabbedPane1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextField tempTextField1;
        // End of variables declaration                   
     
    }
    Prog : liaison série (port com)

    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
    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
    package celsiusconverterproject;
     
    import celsiusconverterproject.CelsiusConverterGUI;
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
     
     
     
    public class SimpleRead 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";
        String  boum;
     
     
     
     	if (args.length > 0)
            {
    	    defaultPort = args[0];
    	} 
     
    	portList = CommPortIdentifier.getPortIdentifiers();
     
     
    	while (portList.hasMoreElements())
            {
    	    portId = (CommPortIdentifier) portList.nextElement();
                //test
                System.out.println((portId.getName()));
                boum = portId.getName();
     
    	    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
                {
    		if (portId.getName().equals(defaultPort))
                    {
    		    System.out.println("Found port: "+defaultPort);
    		    portFound = true;
    		    SimpleRead reader = new SimpleRead();
    		} 
    	    } 
    	} 
    	if (!portFound)
            {
    	    System.out.println("port " + defaultPort + " not found.");
    	} 
     
            (new CelsiusConverterGUI()).setVisible(true);
        } 
     
        public SimpleRead()
        {
    	try
            {
    	    serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
    	}
            catch (PortInUseException e)
            {
            System.out.println("1");
            }
     
    	try
            {
    	    inputStream = serialPort.getInputStream();
    	}
            catch (IOException e)
            {
            System.out.println("2");
            }
     
    	try
            {
    	    serialPort.addEventListener(this);
    	}
            catch (TooManyListenersException e)
            {
            System.out.println("3");
            }
     
    	serialPort.notifyOnDataAvailable(true);
     
    	try
            {
    	    serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, 
    					   SerialPort.STOPBITS_1, 
    					   SerialPort.PARITY_NONE);
    	}
            catch (UnsupportedCommOperationException e)
            {
            System.out.println("4");
            }
     
    	readThread = new Thread(this);
     
    	readThread.start();
        }
     
        public void run() {
    	try {
    	    Thread.sleep(20000);
    	} catch (InterruptedException e)
            {
            System.out.println("5");
            }
        } 
     
        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)
                {
                System.out.println("6");
                }
     
    	    break;
    	}
        }
    /*
        void setVisible(boolean b)
        {
            throw new UnsupportedOperationException("Not yet implemented");
        }*/
     
    }
    voila
    si tu veut plus de détail demande

    merci

  9. #9
    Membre éprouvé Avatar de anisj1m
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2006
    Messages
    1 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 067
    Points : 955
    Points
    955
    Par défaut
    tout d'abord tu doit renomme le methode main dans la deuxieme classe.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    public static void main(String[] args)
    renomme la en:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    public SimpleRead (String a)
    // j'ai ajouté un string pour defferencier cette methode du constructeur déja défini.
    en suite dans la methode ou tu vas mettre ton traitement (clicki d'un boutton par example) tu met:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    public SimpleRead Sr = new SimpleRead ("essaie");

    remarque tu doit faire quelque changement a la fonction main de ta classe SimpleRead car elle contient les parametre String[], args alors tu doit les enlevé

  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
    mais si je renome dans ma 2em classe je vait avoir des erreurs car certain éléménts dépende de args

    Donc des erreurs



    dsl j'avais pas vu que tu l'avai mis en bas

  11. #11
    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
    Bonjour,

    J'ai enfin réussi à l'aide d'un pote à moi donc pour aider les autre personnes qui aurait besoin de cela voici le petit bout de code des 2 fichiers l'un le Main l'autre le Frame :

    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
    package m868;
    import java.util.*;
     
    public class Main
    {
        private List list; 
     
        public Main() {
          this.list = new ArrayList();
          initValeur();
        }
     
        private void initValeur() {
          if (this.list!=null) {
            this.list.add("test1");
            this.list.add("test2");
            this.list.add("test3");
            this.list.add("test4");
            this.list.add("test5");
            this.list.add("test6");        
          }
        }    
     
      public Object[] getListToArray() {
        return this.list.toArray();
      }
     
     
      public List getList() {
        return this.list;
      }
     
      public void addToList(String value) {
        this.list.add(value);
      }
     
        public static void main(String[] args)
        {
           (new Frame()).setVisible(true);   
        }
     
        void setVisible(boolean b)
        {
            throw new UnsupportedOperationException("Not yet implemented");
        }
     
    }
    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
    package m868;
     
    import javax.swing.*;
     
     
    public class Frame extends javax.swing.JFrame
    {
        private Main valeur; 
     
        public Frame()
        {
            this.valeur = new Main();
            initComponents();
        }
     
     
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jComboBox1 = new javax.swing.JComboBox();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jComboBox1 = new JComboBox(this.valeur.getListToArray());
     
            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()
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(234, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(264, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>
     
     
        public static void main(String args[])
        {
            java.awt.EventQueue.invokeLater(new Runnable()
     
            {
                public void run()
                {
                    new Frame().setVisible(true);
     
                }
            });
        }
     
        // Variables declaration - do not modify
        private javax.swing.JComboBox jComboBox1;
        // End of variables declaration
     
    }
    il ne faut pas oublier d'initialisé le jCombobox avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    jComboBox1 = new JComboBox(this.valeur.getListToArray());
    à l'aide des properties car on ne peut pas avoir accés au
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    private void initComponents()
    Merci de votre aide et j'espère que cela aidera certain qui cherche une réponse

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

Discussions similaires

  1. Variable entre deux fichiers java script
    Par Canard64 dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 12/05/2008, 15h58
  2. Faire le lien entre un fichier excel et BO
    Par PlisNuX dans le forum Deski
    Réponses: 1
    Dernier message: 29/05/2007, 13h33
  3. Lien entre 2 fichier .swf
    Par barbo_Africa dans le forum Flash
    Réponses: 1
    Dernier message: 15/05/2007, 12h27
  4. Comment faire le lien entre Prolog et Java ?
    Par nesrin dans le forum Prolog
    Réponses: 2
    Dernier message: 19/03/2007, 18h13
  5. [Upload] Problème de lien entre mes fichiers
    Par temperature dans le forum Langage
    Réponses: 18
    Dernier message: 25/04/2006, 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