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);
}
}
/*----------------------------------------------------------------------------------------------------------*/
} |
Partager