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
|
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Authentification extends JFrame implements ActionListener
{
JButton AAnnuler, AValider, B;
JTextField TF1;
JPasswordField TF2;
Authentification ()
{
TF1 = new JTextField(10);
TF2 = new JPasswordField(10);
JLabel L1 = new JLabel("Login");
JLabel L2 = new JLabel("Password");
JPanel PA1 = new JPanel();
PA1.setLayout(new GridLayout(1,2));
JPanel PA2 = new JPanel();
PA2.setLayout(new GridLayout(1,2));
JPanel PA3 = new JPanel();
AAnnuler = new JButton("Annuler");
AValider = new JButton ("Valider");
PA1.add(L1);
PA1.add(TF1);
PA2.add(L2);
PA2.add(TF2);
PA3.add(AAnnuler);
PA3.add(AValider);
add(PA1, "North");
add(PA2, "Center");
add(PA3, "South");
pack();
setVisible(true);
setResizable(false);
setTitle("Authentification");
AValider.addActionListener(this);
AAnnuler.addActionListener(this);
this.addWindowListener(new Ferm());
}
class Ferm extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
dispose();
}
}
public void actionPerformed(ActionEvent e)
{
B=(JButton)e.getSource();
String T1=TF1.getText();
String T2=TF2.getText();
if(B==AValider)
{
/*Si ti peut je vais changer l'icone ici aussi et merci*/
JOptionPane.showMessageDialog(null, "Salut","Bonjour",JOptionPane.WARNING_MESSAGE);
}
else if (B==AAnnuler)
{
//Celui ci ca marche
/*int Reponse=JOptionPane.showConfirmDialog(this,"Vouler vous vraiment quitter ?","Etiquettes Java",JOptionPane.YES_NO_OPTION);*/
//Dans ce cas la boite de dialog ne s'affiche plus
Icon image = new ImageIcon( getClass().getResource("/img/Quit.png"));
int Reponse=JOptionPane.showConfirmDialog(this,"Vouler vous vraiment quitter ?","Etiquettes Java",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE, image);
if(Reponse==JOptionPane.YES_OPTION)
{
dispose();
}
}
}
public static void main(String []args)
{
Authentification a=new Authentification();
}
} |
Partager