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 :

Bouton qui se répéte


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    70
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Juillet 2009
    Messages : 70
    Par défaut Bouton qui se répéte
    Bonjours a tous.

    Aujourd'hui je suis en forme et donc déjà de retour pour un autre problème .

    Pour mon programme j'utilise une interface graphique avec des boutons.
    Donc j'ai une fenêtre d'accueil ou j'ai le choix entre deux options (choix1 ,choix2).
    Quand je clic sur un des choix( ici choix1) ,je redessine pardessus mes nouveau boutons de choix (bouton1 , bouton2 , retour) , avec bouton1 qui ouvre un JFileChooser. Jusqu'ici tout va bien.
    Mais tous se corse lorsque que je fais retour (donc je redessine ma page d'accueil par dessus ,toujours pas de problème , je reviens sur le même choix1 et lorsque je clic sur bouton1 , mon JFilechooser s'ouvre plusieurs fois (quand je ferme le premier ,un second apparait , puis un troisième ) .
    Donc cela veut dire que mes bouton qui se trouvent dessous sont toujours en fonctionnements.
    J'ai essayée en effacent la fenêtre et en redessinant ,ça fonctionne ,mes comme j'utilise un Look and Feel ma fenêtre ne se redessine pas comme je veux.(j'ai du mal avec le Look and Feel) .

    Donc je voudrais savoir si il y a un moyen pour eviter qu'un bouton qui se trouve sous un autre soit désactivé ,sachant que les deux boutons sont appelés de la même façon ?

    private JButton parcourir = new JButton ("Browse");

    Merci d'avance .

  2. #2
    Membre Expert Avatar de Ivelios
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juillet 2008
    Messages
    1 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 031
    Par défaut
    Bonjour,
    Je n'ai pas touché à JAVA depuis 2 mois donc peux être que ma réponse ne sera pas la bonne (je préviens)

    1/ Tu devrais peux être utiliser un Caneva si tu utilises plusieurs fenêtre.
    2/
    "sachant que les deux boutons sont appelés de la même façon ?"
    si tu veux qu'il soit appelé pareil mais qu'il ne fasse pas la même chose tu peux faire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    private JButton parcourir1 = new JButton ("Browse");
    private JButton parcourir2 = new JButton ("Browse");
     
    parcourir1.setActionCommand("Browse1");
    parcourir2.setActionCommand("Browse2");
    3/ Envoie un peu de code, tu as bien détaillé ton problème mais parfois le code est encore plus explicite, et la solution apparait d'elle même

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    70
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Juillet 2009
    Messages : 70
    Par défaut
    En fait les deux boutons ont la même fonction , mais il sont redessinés les uns sur les autres .
    Je ne redessine pas une autre fenêtre , je ne fait que changer le contenu .

    Voici le code et attention les yeux ça pique

    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
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
     
     
     
    public class FenetreEntre extends JFrame {
     
     
     
    	private Boolean visible = true ;
     
    	private Panneau2 panneau2 = new Panneau2 () ;
    	//private JTextField path = new JTextField () ;
    	//private JPasswordField passwordDuFichier = new JPasswordField () ;
    	private JButton crypte = new JButton("********  [  Crypter un fichier ]  ********"); 
    	private JButton decrypte = new JButton("*******  [ Décrypter un fichier ]  *******");
    	private JButton exit = new JButton("**  [ Exit ]  **");
     
    	public FenetreEntre () {
     
    		this.setTitle("Cryptic");
    	    this.setSize(1000, 600);
    	    this.setLocationRelativeTo(null); // mise au centre de la fenetre
            //this.setLocarion(int x,int y); //pour placer la fenetre
            this.setResizable(false); // empéche le redimentionnement de la fenetre
            //this.setAlwaysOnTop(true); //la fenetre est toujours en premier plan
            this.setUndecorated(true); // retire le contour de la fenetre
    	    this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE);
     
     
    	    panneau2.setLayout( new GridBagLayout ());
    	    panneau2.add(crypte  ,new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 100, 50, 10,  500 ), 0, 0) );
    	    panneau2.add(decrypte  ,new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 270, 50, 10,  500), 0, 0) );
    	    panneau2.add(exit  ,new GridBagConstraints( 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.REMAINDER, new Insets( 80, 0, 0,  0), 0, 0) );
    	    crypte.setBackground(new Color(0,240,0));
    	    decrypte.setBackground(new Color(0,240,0));
    	    exit.setBackground(new Color(0,240,0));
     
    	    Font police = new Font("serif" , Font.ROMAN_BASELINE, 14);
    	    crypte.setFont(police);crypte.setForeground(Color.BLACK);crypte.addActionListener(new Cripter());
    	    decrypte.setFont(police);decrypte.setForeground(Color.BLACK);decrypte.addActionListener(new Decripter());
    	    exit.setFont(police);exit.setForeground(Color.BLACK);exit.addActionListener(new Exit());
     
    	    /*-------look and feel de base-------------------------*/
    		try {
      		   //On force à utiliser le look and feel du system
      		   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      		   //Ici on force tous les composants de notre fenêtre (this) à se redessiner avec le look and feel du système
      		  // SwingUtilities.updateComponentTreeUI(this);
      		} catch (InstantiationException e) {
      		} catch (ClassNotFoundException e) {
      		} catch (UnsupportedLookAndFeelException e) {
      		} catch (IllegalAccessException e) {}   
     
     
     
            afficher(visible);
     
     
    }
    /*---------------------------------------------------------------------------------------------------------*/
    /*------------méthode affichage----------------------------------------------------------------------------*/
     
          private void afficher(Boolean visible2) {
    	        // TODO Raccord de méthode auto-généré
                this.setContentPane(panneau2);
                this.setVisible(true);
       }
    /*---------------------------------------------------------------------------------------------------------*/
    /*------------------bouton Exit----------------------------------------------------------------------------*/
     
          public class Exit implements ActionListener {
     
        		public void actionPerformed(ActionEvent arg0) {
        			// TODO Raccord de méthode auto-généré
     
        			System.exit(0);
        		}
     
        	}
    /*---------------------------------------------------------------------------------------------------------*/
    /*----------------bouton Cripter---------------------------------------------------------------------------*/
          private JTextField pathDuFichier = new JTextField ();
          private JPasswordField firstPassword = new JPasswordField ();
          private JPasswordField ensurePassword = new JPasswordField ();
          private JButton valide = new JButton ("** [ Encrypt ] **");
          private JButton parcourir = new JButton ("* [ Browse ] *");
          private JButton parcourir2 = new JButton ("* [ Browse ] *");
          private JButton retour = new JButton ("** << [Return ] **");
     
          private JTextField nomDuFichierCrypte = new JTextField ();
          private JTextField pathDuFichierCrypte = new JTextField () ;
     
          public class Cripter implements ActionListener {
     
          	public void actionPerformed(ActionEvent arg0) {
          		// TODO Raccord de méthode auto-généré
     
     
     
     
          		panneau2.removeAll() ;
     
          		JScrollPane scrollPath = new JScrollPane (pathDuFichier ) ; 
          		scrollPath.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
     
          		JScrollPane scrollPathCrypte = new JScrollPane (pathDuFichierCrypte ) ; 
          		scrollPathCrypte.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
     
          		pathDuFichier.setPreferredSize(new Dimension (400 , 15));
          		firstPassword.setPreferredSize(new Dimension (200 , 25));
          		ensurePassword.setPreferredSize(new Dimension (200 , 25));
          		pathDuFichierCrypte.setPreferredSize(new Dimension (400 , 15));
          		nomDuFichierCrypte.setPreferredSize(new Dimension (100 , 25));
     
          		valide.setPreferredSize(new Dimension (50 , 25));
          		parcourir.setPreferredSize(new Dimension (25 , 17));
          		parcourir2.setPreferredSize(new Dimension (25 , 17));
          		panneau2.setLayout( new GridBagLayout ());
     
     
          		panneau2.add(scrollPath  ,new GridBagConstraints        ( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets( 50, 120, 0,  0), 0, 10) );
          		panneau2.add(parcourir  ,new GridBagConstraints         ( 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets( 2, 400 , 0,  0), 0, 0) );
          		panneau2.add(firstPassword  ,new GridBagConstraints     ( 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 25, 220, 0,  0), 0, 0) );
          		panneau2.add(ensurePassword  ,new GridBagConstraints    ( 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 40, 220, 0,  0), 0, 0) );
          		panneau2.add(nomDuFichierCrypte  ,new GridBagConstraints( 1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 40, 220, 0,  0), 0, 0) );
          		panneau2.add(scrollPathCrypte  ,new GridBagConstraints  ( 1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 40, 120, 0,  0), 0, 10) );
          		panneau2.add(parcourir2  ,new GridBagConstraints        ( 1, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 2, 400, 0,  0), 0, 0) );
     
          		panneau2.add(valide  ,new GridBagConstraints            ( 1, 7, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 40, 370, 50,  0), 0, 0) );
     
        	    panneau2.add(exit  ,new GridBagConstraints              ( 2, 8, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.REMAINDER, new Insets( 15, 163, 5,  0), 0, 0) );
        	    panneau2.add(retour  ,new GridBagConstraints            ( 0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.REMAINDER, new Insets( 10, 10, 5,  0), 0, 0) );
        	    valide.setBackground(new Color(120,255,10));
        	    exit.setBackground(new Color(0,240,0));
        	    retour.setBackground(new Color(0,240,0));
        	    pathDuFichier.setBackground(new Color(120,255,10));
        	    firstPassword.setBackground(new Color(0,240,0));
        	    ensurePassword.setBackground(new Color(0,240,0));
        	    parcourir.setBackground(new Color(0,240,0));
        	    parcourir2.setBackground(new Color(0,240,0));
        	    pathDuFichierCrypte.setBackground(new Color(120,255,10));
        	    nomDuFichierCrypte.setBackground(new Color(0,240,0));
     
     
        	    Font police = new Font("serif" , Font.ROMAN_BASELINE, 14);
     
        	    valide.setFont(police);valide.setForeground(Color.BLACK);
        	    exit.setFont(police);exit.setForeground(Color.BLACK);exit.addActionListener(new Exit());
        	    retour.setFont(police);retour.setForeground(Color.BLACK);retour.addActionListener(new Return());
        	    pathDuFichier.setFont(police);pathDuFichier.setForeground(Color.BLACK);pathDuFichier.setHorizontalAlignment(JPasswordField.CENTER);
        	    firstPassword.setFont(police);firstPassword.setForeground(Color.BLACK);firstPassword.setHorizontalAlignment(JPasswordField.CENTER);
        	    ensurePassword.setFont(police);ensurePassword.setForeground(Color.BLACK);ensurePassword.setHorizontalAlignment(JPasswordField.CENTER);
        	    parcourir.setFont(police);parcourir.setForeground(Color.BLACK);
        	    parcourir2.setFont(police);parcourir2.setForeground(Color.BLACK);
        	    pathDuFichierCrypte.setFont(police);pathDuFichierCrypte.setForeground(Color.BLACK);pathDuFichierCrypte.setHorizontalAlignment(JPasswordField.CENTER);
        	    nomDuFichierCrypte.setFont(police);nomDuFichierCrypte.setForeground(Color.BLACK);nomDuFichierCrypte.setHorizontalAlignment(JPasswordField.CENTER);
     
        	    panneau2.setPath("Path du fichier à Crypter  :");
        	    panneau2.setPassFirst("Password  :");
        	    panneau2.setPassEnsure("Confirmer password  :");
        	    panneau2.setNomFichier("Nom du fichier Crypté  :");
        	    panneau2.setPathCrypte("Path du fichier Crypté  :");
     
     
        	    valide.addActionListener(new ValiderSaisie());
        	    parcourir.addActionListener(new SearchFile());
        	    parcourir2.addActionListener(new SearchDirectory());
     
                afficher(visible);
     
     
          	}
     
          }
     
    /*--------------------------------------------------------------------------------------------------------*/
    /*---------------------bouton validation de la saisie-----------------------------------------------------*/
          public class ValiderSaisie implements ActionListener {
     
          	public void actionPerformed(ActionEvent arg0) {
          		// TODO Raccord de méthode auto-généré
     
     
     
          //----------si les 2 mots de passe ne sont pas identique
          		if (!firstPassword.getText().equals(ensurePassword.getText()))  {
          			firstPassword.setText("");
          			ensurePassword.setText("");
          			panneau2.setValide1("Les deux Password ");
          			panneau2.setValide2("ne sont pas identiques ??");
     
          			repaint();
          		}// fin du if
     
          //----------si un des 2 passe est vide
     
          		if(firstPassword.getText().equals("") || ensurePassword.getText().equals("") || (pathDuFichier.getText()).equals("") 
          				|| nomDuFichierCrypte.getText().equals("") ||pathDuFichierCrypte.equals("") ) {
          			JOptionPane.showMessageDialog(null,"Un ou plusieurs champs sont vides :\n        Corrigez l'erreur" ,"Attention ",JOptionPane.ERROR_MESSAGE);
          			panneau2.setValide1("");
          			panneau2.setValide2("");
          			repaint();
          		}// fin du if
     
          //----------si les 2 mots de passe sont identiques et que tous les champs sont bien remplis
          		else {
     
          			Crypte crypte = new Crypte (pathDuFichier.getText() , pathDuFichierCrypte.getText() , firstPassword.getText()) ;
     
          			panneau2.setValide1("");
          			panneau2.setValide2("");
          			pathDuFichier.setText("");
          	        firstPassword.setText("");
          	        ensurePassword.setText("");
          	        nomDuFichierCrypte.setText("");
          	        pathDuFichierCrypte.setText("");
     
     
     
          		}// fin du else
          	}
     
          }
     /*-------------------------------------------------------------------------------------------------------*/
     /*------------------bouton Search------------------------------------------------------------------------*/
     
     
     
     
          public class SearchFile implements ActionListener {
     
          	public void actionPerformed(ActionEvent arg0) {
          		// TODO Raccord de méthode auto-généré
     
     
         	//--------ouverture de la boite JFileChooser
          		JFileChooser choixDuFichier = new JFileChooser();
          		int resultat = choixDuFichier.showSaveDialog(null );
     
     
     
     
         	//--------on récupère le choix
          	//--------on le met en String
          	//--------on l'écrit dans le path
          		File nomDuFichier = choixDuFichier.getSelectedFile();
          		String fichier = String.valueOf(nomDuFichier);
          		pathDuFichier.setText(fichier);
     
       //-----bon ça marche bien comme ça
          		pathDuFichier.setPreferredSize(new Dimension (((pathDuFichier.getText().length())*7 +pathDuFichier.getText().length()) , 25));
     
          	}
          }
    /*---------------------------------------------------------------------------------------------------------*/
    /*-----------bouton search directory-----------------------------------------------------------------------*/
     
          public class SearchDirectory implements ActionListener {
     
          	public void actionPerformed(ActionEvent arg0) {
          		// TODO Raccord de méthode auto-généré
     
          	//--------ouverture de la boite JFileChooser
           		JFileChooser choixDuDossier = new JFileChooser();
           		choixDuDossier.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);// pour selectionner que les dossiers
           		int resultat = choixDuDossier.showSaveDialog(null );
     
     
     
    //       	--------on récupère le choix
              	//--------on le met en String
              	//--------on l'écrit dans le path
              		File nomDuFichier = choixDuDossier.getSelectedFile();
              		String fichier = String.valueOf(nomDuFichier);
             		pathDuFichierCrypte.setText(fichier+"/"+nomDuFichierCrypte.getText());
     
             	   //-----bon ça marche bien comme ça
             	     pathDuFichierCrypte.setPreferredSize(new Dimension (((pathDuFichier.getText().length())*7 +pathDuFichier.getText().length()) , 25));
     
     
          	}
     
          }
    /*---------------------------------------------------------------------------------------------------------*/
    /*----------------bouton Decripter---------------------------------------------------------------------------*/
     
          private JButton valide2 = new JButton ("** [ Decrypting ] **");
     
          public class Decripter implements ActionListener {
     
        		public void actionPerformed(ActionEvent arg0) {
        			// TODO Raccord de méthode auto-généré
     
        			panneau2.removeAll() ;
        			JScrollPane scrollPath = new JScrollPane (pathDuFichier ) ; 
              		scrollPath.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
     
              		JScrollPane scrollPathCrypte = new JScrollPane (pathDuFichierCrypte ) ; 
              		scrollPathCrypte.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
     
              		pathDuFichier.setPreferredSize(new Dimension (400 , 15));
              		firstPassword.setPreferredSize(new Dimension (200 , 25));
              		pathDuFichierCrypte.setPreferredSize(new Dimension (400 , 15));
              		nomDuFichierCrypte.setPreferredSize(new Dimension (100 , 25));
     
              		valide.setPreferredSize(new Dimension (50 , 25));
              		parcourir.setPreferredSize(new Dimension (25 , 17));
              		parcourir2.setPreferredSize(new Dimension (25 , 17));
              		panneau2.setLayout( new GridBagLayout ());
     
     
              		panneau2.add(scrollPath  ,new GridBagConstraints        ( 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets( 50, 130, 0,  0), 0, 10) );
              		panneau2.add(parcourir  ,new GridBagConstraints         ( 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets( 2, 410 , 0,  0), 0, 0) );
              		panneau2.add(firstPassword  ,new GridBagConstraints     ( 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 30, 230, 0,  0), 0, 0) );
              		panneau2.add(nomDuFichierCrypte  ,new GridBagConstraints( 1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 100, 230, 0,  0), 0, 0) );
              		panneau2.add(scrollPathCrypte  ,new GridBagConstraints  ( 1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 40, 130, 0,  0), 0, 10) );
              		panneau2.add(parcourir2  ,new GridBagConstraints        ( 1, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 2, 410, 0,  0), 0, 0) );
     
              		panneau2.add(valide2  ,new GridBagConstraints            ( 1, 7, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 40, 380, 50,  0), 0, 0) );
     
            	    panneau2.add(exit  ,new GridBagConstraints              ( 2, 8, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.REMAINDER, new Insets( 12, 147, 5,  0), 0, 0) );
            	    panneau2.add(retour  ,new GridBagConstraints            ( 0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.REMAINDER, new Insets( 10, 10, 5,  0), 0, 0) );
     
            	    valide2.setBackground(new Color(120,255,10));
            	    exit.setBackground(new Color(0,240,0));
            	    retour.setBackground(new Color(0,240,0));
            	    pathDuFichier.setBackground(new Color(120,255,10));
            	    firstPassword.setBackground(new Color(0,240,0));
            	    ensurePassword.setBackground(new Color(0,240,0));
            	    parcourir.setBackground(new Color(0,240,0));
            	    parcourir2.setBackground(new Color(0,240,0));
            	    pathDuFichierCrypte.setBackground(new Color(120,255,10));
            	    nomDuFichierCrypte.setBackground(new Color(0,240,0));
     
     
            	    Font police = new Font("serif" , Font.ROMAN_BASELINE, 14);
     
            	    valide2.setFont(police);valide2.setForeground(Color.BLACK);
            	    exit.setFont(police);exit.setForeground(Color.BLACK);exit.addActionListener(new Exit());
            	    retour.setFont(police);retour.setForeground(Color.BLACK);retour.addActionListener(new Return());
            	    pathDuFichier.setFont(police);pathDuFichier.setForeground(Color.BLACK);pathDuFichier.setHorizontalAlignment(JPasswordField.CENTER);
            	    firstPassword.setFont(police);firstPassword.setForeground(Color.BLACK);firstPassword.setHorizontalAlignment(JPasswordField.CENTER);
            	    parcourir.setFont(police);parcourir.setForeground(Color.BLACK);
            	    pathDuFichierCrypte.setFont(police);pathDuFichierCrypte.setForeground(Color.BLACK);pathDuFichierCrypte.setHorizontalAlignment(JPasswordField.CENTER);
            	    nomDuFichierCrypte.setFont(police);nomDuFichierCrypte.setForeground(Color.BLACK);nomDuFichierCrypte.setHorizontalAlignment(JPasswordField.CENTER);
     
            	    panneau2.setPath("Path du fichier à Décrypter  :");
            	    panneau2.setPassFirst("Password  :");
            	    panneau2.setNomFichier("Nom du fichier Décrypté  :");
            	    panneau2.setPathCrypte("Path du fichier Décrypté  :");
     
     
            	    valide2.addActionListener(new ValiderSaisieDecryptage());
            	    parcourir.addActionListener(new SearchFile());
            	    parcourir2.addActionListener(new SearchDirectory());
     
                    afficher(visible);
     
     
              	}
     
     
        	}
    /*---------------------------------------------------------------------------------------------------------*/
    /*---------------bouton validation de la saisie de Décryptage----------------------------------------------*/
     
          public class ValiderSaisieDecryptage implements ActionListener {
     
          	public void actionPerformed(ActionEvent arg0) {
          		// TODO Raccord de méthode auto-généré
     
          		 //----------si le mot de passe est valide et que tous les champs sont bien remplis
          		// à finir
          			//pathDuFichierCrypte ets ici le fichier à décrypté
     
     
     
     
          		if ( pathDuFichier.getText().equals("") ||nomDuFichierCrypte.getText().equals("") || pathDuFichierCrypte.getText().equals("") || firstPassword.getText().equals(""))	{
          			JOptionPane.showMessageDialog(null,"Un ou plusieurs champs sont vides :\n        Corrigez l'erreur" ,"Attention ",JOptionPane.ERROR_MESSAGE);
     
          		}// fin du if
     
          		else {
          		Decrypte decrypte = new Decrypte (pathDuFichier.getText() , pathDuFichierCrypte.getText() , firstPassword.getText()) ;
     
          		}
     
          		panneau2.setValide1("");
      			panneau2.setValide2("");
      			pathDuFichier.setText("");
      	        firstPassword.setText("");
      	        ensurePassword.setText("");
      	        nomDuFichierCrypte.setText("");
      	        pathDuFichierCrypte.setText("");
     
      	        repaint();
          	}
     
          }
     
    /*---------------------------------------------------------------------------------------------------------*/
    /*-------------------------bouton Return-------------------------------------------------------------------*/
     
     
          public class Return implements ActionListener {
     
          	public void actionPerformed(ActionEvent arg0) {
          		// TODO Raccord de méthode auto-généré
     
     
     
          		panneau2.removeAll();
     
          		panneau2.setPath("");
         	    panneau2.setPassFirst("");
         	    panneau2.setPassEnsure("");
         	    panneau2.setNomFichier("");
         	    panneau2.setPathCrypte("");
     
     
         	   /*--------on supprime toutes les saisisprécedentes ---------*/
         	    panneau2.setValide1("");
     			panneau2.setValide2("");
     			pathDuFichier.setText("");
     	        firstPassword.setText("");
     	        ensurePassword.setText("");
     	        nomDuFichierCrypte.setText("");
     	        pathDuFichierCrypte.setText("");
     
     
     
          		panneau2.setLayout( new GridBagLayout ());
         	    panneau2.add(crypte  ,new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 100, 50, 10,  500 ), 0, 0) );
         	    panneau2.add(decrypte  ,new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 270, 50, 10,  500), 0, 0) );
         	    panneau2.add(exit  ,new GridBagConstraints( 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.REMAINDER, new Insets( 80, 0, 0,  0), 0, 0) );
         	    crypte.setBackground(new Color(0,240,0));
         	    decrypte.setBackground(new Color(0,240,0));
         	    exit.setBackground(new Color(0,240,0));
     
         	    Font police = new Font("serif" , Font.ROMAN_BASELINE, 14);
         	    crypte.setFont(police);crypte.setForeground(Color.BLACK);crypte.addActionListener(new Cripter());
         	    decrypte.setFont(police);decrypte.setForeground(Color.BLACK);decrypte.addActionListener(new Decripter());
         	    exit.setFont(police);exit.setForeground(Color.BLACK);exit.addActionListener(new Exit());
     
     
                 afficher(visible);
     
          	}
     
          }
     
    /*----------------------------------------------------------------------------------------------------------*/
    }
    Si vous vous y retrouvez c'est cool.

    Là , je doit m'absenter jusqu'à demain , alors je regarderais ça plus tard.
    Merci pour la réponse .

  4. #4
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Par défaut
    Tu dois construire ton interface graphique une fois pour toute. Abandonne les constructions dynamiques.
    ensuite, pour la gestion des 2 panneaux différents, utilise un CardLayout, c'est fait pour ça.
    Tu construits une fois pour toutes différents JPanel, tu les places dans un CardLayout, et tu changes de JPanel en appelant la bonne méthode sur le CardLayout. Tu es ainsi assuré qu'un bouton caché ne va pas s'activer par magie.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java
    Que la force de la puissance soit avec le courage de ta sagesse.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    70
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Juillet 2009
    Messages : 70
    Par défaut
    Oups désolé dinobogan de ne pas avoir répondu plus tôt .

    Avant de te répondre j'ai du regarder comment fonctionné CardLayout ,puisque comme tout bon débutant qui se respecte , Je ne connaissais pas.
    Merci à la javadoc .

    Oui en effet c'est une bonne alternative à la solution ,mais je n'ai pas réussi a avoir le rendu voulu .
    Mais de toute façon cette classe me servira pour mes futures prog.

    Pour résoudre mon problème ,je me suis résous donc a créer une autre fenêtre en suppriment la précédente ,et comme ça plus de problème.Je sait que les solutions les plus simples ne sont pas les meilleurs ,mais pour un débutant cela suffit .

    Merci encore de vous êtres attardé sur mon problème, et encore désolut de répondre si tard.
    Amicalement .

Discussions similaires

  1. Créer pour un bouton une image entière ou qui se répète via CSS
    Par sam01 dans le forum Webdesign & Ergonomie
    Réponses: 4
    Dernier message: 03/05/2010, 19h18
  2. Api Win32 : boutons "qui bougent" au passage de la
    Par Spartan03 dans le forum Windows
    Réponses: 9
    Dernier message: 06/06/2005, 23h52
  3. Réponses: 10
    Dernier message: 10/06/2004, 16h20
  4. Réponses: 2
    Dernier message: 26/09/2003, 16h49

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