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

JBuilder Java Discussion :

probléme dans textarea


Sujet :

JBuilder Java

  1. #1
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Décembre 2008
    Messages
    83
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2008
    Messages : 83
    Points : 53
    Points
    53
    Par défaut probléme dans textarea
    bonsoir
    j'ai un probléme au niveau textarea telleque lorsque je lance l'execution du boutton ajouter m'affiche deux fois la ligne que je voudrai l'afficher
    sa c'est mon code source

    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
    package inerface;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    
    import java.io.*;
    
    import java.lang.Object;
    
    
    public class Cadre2 extends JFrame {
      JPanel contentPane;
      JPanel jPanel1 = new JPanel();
      public JTextField nomclasse2 = new JTextField();
      JLabel jLabel2 = new JLabel();
      public JTextField nomclasse1 = new JTextField();
      JComboBox jComboBox1 = new JComboBox();
      Border border1;
      JButton ajouter = new JButton();
      JButton modifier = new JButton();
      JButton supprimer = new JButton();
      JLabel jLabel4 = new JLabel();
      JLabel jLabel3 = new JLabel();
      JButton sauvegarder = new JButton();
      JButton charger = new JButton();
      private JTextArea jTextArea1 = new JTextArea();
      JScrollPane jScrollPane1 = new JScrollPane();
      private final static String newline = "\n";
      private final static String espace = "\t";
      private final static String esp = " ";
      JButton effacer = new JButton();
      Border border2;
    
        //Construire le cadre
      public Cadre2() {
           try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
        Dimension d= Toolkit.getDefaultToolkit().getScreenSize();
           this.setSize(d );
      }
      //Initialiser le composant
      private void jbInit() throws Exception  {
        contentPane = (JPanel) this.getContentPane();
        border1 = BorderFactory.createLineBorder(SystemColor.controlText,1);
        border2 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.blue,1),BorderFactory.createEmptyBorder(2,2,2,2));
        contentPane.setLayout(null);
        this.getContentPane().setBackground(UIManager.getColor("ComboBox.selectionBackground"));
        this.setTitle("Interface utilisateur");
    
        jPanel1.setBackground(SystemColor.window);
        jPanel1.setBounds(new Rectangle(4, 3, 1041, 772));
        jPanel1.setLayout(null);
    
        //On redéfinit la méthode insertString
                PlainDocument myDoc = new PlainDocument() {
                        //On redéfinit la méthode insertString
                        public void insertString(int offs, String str, AttributeSet a)
                  throws BadLocationException
                        {
                                //on teste que la chaine est contient seulement des caractères, ou des espaces
                                //le \s représente les espaces (espace, tabulations ...)
                                if (str.matches("[A-Za-z\\s\\_]+"))
                                        //si oui, on insère la chaine
                                        super.insertString(offs, str, a);
                        }
                };
    
        nomclasse2.setToolTipText("Saisé le Nom du classe");
        nomclasse2.setForeground(Color.blue);
        nomclasse2.setBounds(new Rectangle(752, 69, 136, 32));
        nomclasse2.setFont(new Font("Times New Roman", 2, 24));
        nomclasse2.setDocument(myDoc);
    
        jLabel2.setText("   Règle :");
        jLabel2.setVerticalAlignment(SwingConstants.CENTER);
        jLabel2.setBounds(new Rectangle(-3, 69, 115, 39));
        jLabel2.setFont(new java.awt.Font("SansSerif", 1, 25));
    
        //On redéfinit la méthode insertString
                PlainDocument myDoc1 = new PlainDocument() {
                        //On redéfinit la méthode insertString
                        public void insertString(int offs, String str, AttributeSet a)
                  throws BadLocationException
                        {
                                //on teste que la chaine est contient seulement des caractères, ou des espaces
                                //le \s représente les espaces (espace, tabulations ...)
                                if (str.matches("[A-Za-z\\s\\_]+"))
                                        //si oui, on insère la chaine
                                        super.insertString(offs, str, a);
    
                              if (str.matches(" ")){
                              System.out.println("Erreur : vous avez pas saisé le Nom du la Classe");
                              }
                        }
                };
    
        nomclasse1.setToolTipText("Saisé le Nom du classe");
        nomclasse1.setForeground(Color.blue);
        nomclasse1.setBounds(new Rectangle(110, 71, 137, 32));
        nomclasse1.setFont(new Font("Times New Roman", 2, 24));
        nomclasse1.setDocument(myDoc1);
    
        jTextArea1.setFont(new Font("Times New Roman", 2, 24));
        jTextArea1.setEditable(false);
    
        jComboBox1.setForeground(Color.blue);
        jComboBox1.setBounds(new Rectangle(265, 70, 464, 33));
        jComboBox1.setFont(new Font("Times New Roman", 2, 24));
    
        contentPane.setBackground(Color.lightGray);
    
        ajouter.addActionListener(new Cadre2_ajouter_actionAdapter(this));
        ajouter.setText("Ajouter");
        ajouter.addActionListener(new Cadre2_ajouter_actionAdapter(this));
        ajouter.setFont(new java.awt.Font("Dialog", 1, 24));
        ajouter.setBackground(SystemColor.inactiveCaptionText);
        ajouter.setBounds(new Rectangle(237, 137, 179, 44));
        ajouter.setToolTipText("Ajouter une régle");
    
        modifier.setText("Modifier");
        modifier.addActionListener(new Cadre2_modifier_actionAdapter(this));
        modifier.setFont(new java.awt.Font("Dialog", 1, 24));
        modifier.setBackground(SystemColor.inactiveCaptionText);
        modifier.setBounds(new Rectangle(414, 137, 179, 44));
        modifier.setToolTipText("Modifier une régle");
    
        supprimer.setText("Ajouter Attribut");
        supprimer.addActionListener(new Cadre2_supprimer_actionAdapter(this));
        supprimer.setFont(new java.awt.Font("Dialog", 1, 24));
        supprimer.setBackground(SystemColor.inactiveCaptionText);
        supprimer.setBounds(new Rectangle(593, 138, 226, 43));
        supprimer.setToolTipText("Supprimer une régle");
    
        jLabel4.setHorizontalTextPosition(SwingConstants.CENTER);
        jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel4.setBounds(new Rectangle(38, 246, 262, 32));
        jLabel4.setText("Base de vos règle");
        jLabel4.setFont(new java.awt.Font("Dialog", 2, 25));
    
        jLabel3.setHorizontalTextPosition(SwingConstants.CENTER);
        jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel3.setBounds(new Rectangle(60, 9, 527, 49));
        jLabel3.setText("Entré Les règle d\'un cahier de charge");
        jLabel3.setFont(new java.awt.Font("Dialog", 2, 26));
    
        sauvegarder.setBackground(SystemColor.inactiveCaptionText);
        sauvegarder.setBounds(new Rectangle(485, 500, 198, 40));
        sauvegarder.setFont(new java.awt.Font("Dialog", 1, 24));
        sauvegarder.setText("Sauvegarder ");
        sauvegarder.addActionListener(new Cadre2_sauvegarder_actionAdapter(this));
        sauvegarder.setToolTipText("Sauvegarder vos régle");
    
        charger.setBackground(SystemColor.inactiveCaptionText);
        charger.setBounds(new Rectangle(682, 500, 191, 39));
        charger.setFont(new java.awt.Font("Dialog", 1, 24));
        charger.setText("Charger");
        charger.addActionListener(new Cadre2_charger_actionAdapter(this));
        charger.setToolTipText("Charger les ancien régle saisée");
    
        jScrollPane1.setAlignmentX((float) 0.8);
        jScrollPane1.setBorder(border2);
        jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setBounds(new Rectangle(8, 281, 860, 209));
        jScrollPane1.getViewport().setBackground(SystemColor.inactiveCaptionText);
    
        effacer.setBounds(new Rectangle(872, 502, 191, 37));
        effacer.setText("Effacer");
        effacer.addActionListener(new Cadre2_effacer_actionAdapter(this));
        effacer.setBackground(SystemColor.inactiveCaptionText);
        effacer.setFont(new java.awt.Font("Dialog", 1, 24));
        effacer.setToolTipText("Effacer le contenu ");
    
        jPanel1.add(nomclasse1, null);
        jPanel1.add(jLabel2, null);
        jPanel1.add(ajouter, null);
        jPanel1.add(supprimer, null);
        jPanel1.add(modifier, null);
        jPanel1.add(jLabel3, null);
        jPanel1.add(sauvegarder, null);
        jPanel1.add(charger, null);
        jPanel1.add(jComboBox1, null);
        jPanel1.add(nomclasse2, null);
        jPanel1.add(effacer, null);
        jPanel1.add(jScrollPane1, null);
        jPanel1.add(jLabel4, null);
        jScrollPane1.getViewport().add(jTextArea1, null);
        contentPane.add(jPanel1, null);
    
        jComboBox1.setToolTipText("Entrer le type d'association ou les cardinalité ");
        jComboBox1.addItem("est_en_relation_avec ");
        jComboBox1.addItem("est_fait_de ");
        jComboBox1.addItem("posséde");
        jComboBox1.addItem("est_composé_de  ");
        jComboBox1.addItem("est_construit_avec ");
        jComboBox1.addItem("est_un  ");
        jComboBox1.addItem("est_une_sorte_de ");
        jComboBox1.addItem("spécifier_par ");
        jComboBox1.addItem("un_et_un_seul ");
        jComboBox1.addItem("optionnel ");
        jComboBox1.addItem("au_plus_un_ou_plusieur  ");
        jComboBox1.addItem("au_moin_1  ");
        jComboBox1.addItem(" entre_n_et_m ");
      }
    /////////////////////////////////////////
      public String recupérer(){
        String clas;
    
           clas=nomclasse1.getText();
    
               return clas;
           }
    
      ///////////////////////////////////////////
    
      void charger_actionPerformed(ActionEvent e) {
    
       JFileChooser jfilechooser = new JFileChooser();
           if (jfilechooser.showOpenDialog(this) == jfilechooser.APPROVE_OPTION) {
                try {
                     BufferedReader buffRead =
                  new BufferedReader(new FileReader(jfilechooser.getSelectedFile()));
                    StringBuffer stringBuffer = new StringBuffer();
                         while (buffRead.ready()) {
                                 String ligne;
                                    ligne =buffRead.readLine();
                                       stringBuffer.append(ligne);
                                        stringBuffer.append("\n");
                                    }
                                         buffRead.close();
                                   jTextArea1.setText(stringBuffer.toString());
                                         }
                                catch (Exception ex) {
                                }
                            }
    
    
    }
      ///////////////////////////////////////////
    
      void quitter_actionPerformed(ActionEvent e) {
    this.hide();
      }
    /////////////////////////////////////////////
    
      void ajouter_actionPerformed(ActionEvent e) {
      jTextArea1.append("X="+nomclasse1.getText()+" "+";"+" "+"Y="+jComboBox1.getSelectedItem()+" "+";"+" "+"Z="+nomclasse2.getText()+";" + newline);
     }/////////////////////////////////////////////
      void sauvegarder_actionPerformed(ActionEvent e) {
        BufferedReader FichierText = null;
        JFileChooser c1 = new JFileChooser();
                          if (c1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                              try {
                                    BufferedWriter ecriture = null;
                                //ouverture du fichier en ecriture
                                  ecriture =new BufferedWriter(new FileWriter(c1.getSelectedFile()));
                                 String text=jTextArea1.getText();
                                 ecriture.write( text);
                                 ecriture.newLine();
                                 ecriture.close();
                              }
    
                              catch (Exception ex) {
                                  jTextArea1.setText("" + ex);
                              }
                          }
    
      }
    
      void effacer_actionPerformed(ActionEvent e) {
    jTextArea1.setText("");
      }
    
      void supprimer_actionPerformed(ActionEvent e) {
        JFrame Cadre3 = new Cadre3();
        Cadre3.setVisible(true);
    
      }
    
      void modifier_actionPerformed(ActionEvent e) {
        jTextArea1.setEditable(true);
      }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////
    }
    
    class Cadre2_ajouter_actionAdapter implements java.awt.event.ActionListener {
      Cadre2 adaptee;
    
      Cadre2_ajouter_actionAdapter(Cadre2 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.ajouter_actionPerformed(e);
      }
    }
    
    class Cadre2_sauvegarder_actionAdapter implements java.awt.event.ActionListener {
      Cadre2 adaptee;
    
      Cadre2_sauvegarder_actionAdapter(Cadre2 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.sauvegarder_actionPerformed(e);
      }
    }
    
    class Cadre2_charger_actionAdapter implements java.awt.event.ActionListener {
      Cadre2 adaptee;
    
      Cadre2_charger_actionAdapter(Cadre2 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.charger_actionPerformed(e);
      }
    }
    
    class Cadre2_effacer_actionAdapter implements java.awt.event.ActionListener {
      Cadre2 adaptee;
    
      Cadre2_effacer_actionAdapter(Cadre2 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.effacer_actionPerformed(e);
      }
    }
    
    class Cadre2_supprimer_actionAdapter implements java.awt.event.ActionListener {
      Cadre2 adaptee;
    
      Cadre2_supprimer_actionAdapter(Cadre2 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.supprimer_actionPerformed(e);
      }
    }
    
    class Cadre2_modifier_actionAdapter implements java.awt.event.ActionListener {
      Cadre2 adaptee;
    
      Cadre2_modifier_actionAdapter(Cadre2 adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.modifier_actionPerformed(e);
      }
    }
    s'il vous plait répondé moi.
    merci d'avance
    la vie nous permetre d'instruire nespas !!

  2. #2
    Membre éclairé Avatar de herch
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    655
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : Canada

    Informations forums :
    Inscription : Mai 2006
    Messages : 655
    Points : 773
    Points
    773
    Par défaut Problème de concentration
    Salut,
    C'est tout bête, mais apparemment, t'es pas bien concentré.
    remarque ces lignes
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    ajouter.addActionListener(new Cadre2_ajouter_actionAdapter(this));
        ajouter.setText("Ajouter");
        ajouter.addActionListener(new Cadre2_ajouter_actionAdapter(this));
    Tu as mis addActionListener 2 fois, du coup, il affiche le résultat 2 fois.
    Il te suffit donc d'enlever une des deux.. taraaaa

  3. #3
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Décembre 2008
    Messages
    83
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2008
    Messages : 83
    Points : 53
    Points
    53
    Par défaut
    Bonsoir
    Vraiment c’est une Erreur bête je n’ai pas remarqué
    Merci beaucoup
    cordialement
    la vie nous permetre d'instruire nespas !!

Discussions similaires

  1. Problème alinéa dans textarea
    Par guitaros dans le forum Balisage (X)HTML et validation W3C
    Réponses: 7
    Dernier message: 23/12/2004, 00h07
  2. problème dans l'hebergement
    Par Redouane dans le forum ASP
    Réponses: 9
    Dernier message: 31/12/2003, 23h34
  3. Quel est le problème dans ce code ?
    Par Luther13 dans le forum C
    Réponses: 12
    Dernier message: 26/08/2003, 16h09
  4. Problème dans analisys Manager
    Par ien_ien23 dans le forum MS SQL Server
    Réponses: 7
    Dernier message: 11/07/2003, 14h38
  5. Problème dans requête avec count()
    Par BadFox dans le forum Requêtes
    Réponses: 3
    Dernier message: 08/07/2003, 18h02

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