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
|
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.*;
public class FenetreSaisie extends JFrame implements ActionListener
{
private JPanel container = null;//Déclaration de lobjet JPanel
private FlowLayout layout = null ;//Déclaration de notre layout
private JLabel texte = null;
private JButton validate = null ;
private JButton exit = null;
private JTextField newpassword = null;
public String password;
private JLabel image = new JLabel(new ImageIcon("C:/Password Archivage/Goss-banner.jpg"));
private FenetreSaisie() throws IOException
{
super();
build();
}
public static void main(String[] args) throws IOException
{
FenetreSaisie gui = new FenetreSaisie();
gui.setVisible(true);
}
private void build(){
this.setTitle("Archivage du mot de passe");
this.setSize(520,200);
this.setLocationRelativeTo(null); //On centre la fenêtre sur lécran
this.setResizable(false) ;
this.setContentPane(getContainer()) ;//On lui dit de mettre le panel en fond
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private JPanel getContainer()
{
layout = new FlowLayout() ; //Instanciation du layout
layout.setAlignment(FlowLayout.LEFT) ;
container = new JPanel() ;
container.setLayout(layout);
container.add(image);
texte =new JLabel("Merci de ressaisir le mot de passe pour archivage");
texte.setPreferredSize(new Dimension(520,25));
container.add(texte);
newpassword = new JTextField();
newpassword.setPreferredSize(new Dimension(380,25));
container.add(newpassword);
password = newpassword.getText();
validate = new JButton("Valider");
validate.setPreferredSize(new Dimension(125,25));
validate.addActionListener(this) ;
container.add(validate);
exit = new JButton("Quitter");
exit.setPreferredSize(new Dimension(125,25));
exit.addActionListener(this) ;
container.add(exit);
return container ;
}
public void fichier() throws IOException
{
BufferedWriter out = new BufferedWriter(new FileWriter("//10.58.114.24/DOCLAND/Workflow/Hardware_Backup PC Workflow/Ghost/PC Build Machine/Password.txt"));
String s = "Mot de passe actuel de la Build Machine:";
out.write(s);
out.newLine();
out.write(password);
out.close();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==validate)
{
try
{
password = newpassword.getText();
fichier();
} catch (IOException e1) {
e1.printStackTrace();
}
System.exit(0);
}
if(e.getSource()==exit)
{
System.exit(0);
}
}
} |