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
| public class Login extends JFrame implements ActionListener {
Connection con;
JPanel pCenter;
Image imageFond;
Image imageTest;
Color JAVAONE_BLUE = new Color(46, 49, 146);
static JTextField login=creertextField(10,Color.white,Color.black,BorderFactory.createBevelBorder(1));
static JPasswordField mdp=creerpassField(10,Color.white,Color.black,BorderFactory.createBevelBorder(1));
static JButton Connexion=new BoutonDegrade("Connexion" ,Color.WHITE, new Color(54, 114, 224), Color.DARK_GRAY,105);
static JButton Annuler=new BoutonDegrade("Annuler",Color.WHITE, new Color(54, 114, 224), Color.DARK_GRAY,90);
//Font f1=new Font("Arabic Transparent",Font.BOLD,14);
Login(){
try {
imageFond = ImageIO.read(getClass().getResourceAsStream("/images/Login.jpg"));
} catch (IOException e) {e.printStackTrace();}
pCenter =new JPanel();
pCenter.setLayout(null);
JLabel login_label=new JLabel("Nom utilisateur :");
//login_label.setFont(f1);
login_label.setBounds(80, 153, 120, 25);
pCenter.add(login_label);
login.setBounds(200, 153, 205, 25);
pCenter.add(login);
JLabel mdp_label=new JLabel("Mot de passe :");
mdp_label.setBounds(80,183,100,25);
pCenter.add(mdp_label);
mdp.setBounds(200, 183, 205, 25);
pCenter.add(mdp);
mdp.addActionListener(this);
Connexion.setEnabled(true);
//Connexion=new JButton("Connexion");
Connexion.setBounds(200, 260, 105, 27);
pCenter.add(Connexion);
Connexion.addActionListener(this);
Annuler.setEnabled(true);
//Annuler=new JButton("Annuler");
Annuler.setBounds(315, 260, 90, 27);
pCenter.add(Annuler);
Faire_Fond o = new Faire_Fond(imageFond);
pCenter.add(o);
setContentPane(pCenter);
}
class Faire_Fond extends JPanel {
private Image img;
public Faire_Fond(String img) {
this(new ImageIcon(img).getImage());
}
public Faire_Fond(Image img) {
this.img = img;
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
}
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
}
}
public JLabel creerLabel(String titre){
JLabel l=new JLabel(titre);
//l.setFont(font1);
l.setForeground(JAVAONE_BLUE);
return l;
}
public static JTextField creertextField(int longueur,Color couleur1,Color couleur2,Border bordure){
JTextField tf=new JTextField(longueur);
tf.setBorder(bordure);
//tf.setFont(font1);
tf.setBackground(couleur1);
tf.setForeground(couleur2);
return tf;
}
public static JPasswordField creerpassField(int longueur,Color couleur1,Color couleur2,Border bordure){
JPasswordField tf=new JPasswordField(longueur);
tf.setBorder(bordure);
//tf.setFont(font1);
tf.setBackground(couleur1);
tf.setForeground(couleur2);
return tf;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Login inn=new Login();
inn.setTitle("Connecter au Banque 2009");
inn.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
inn.setSize(470,335);
try {
UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
} catch (UnsupportedLookAndFeelException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
inn.center();
final Faire_Bouton f=new Faire_Bouton();
ImageIcon bank=f.readImageIcon("bank2.jpg");
inn.setIconImage(bank.getImage());
inn.setVisible(true);
}
public void center() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
int x = (screenSize.width - frameSize.width) / 2;
int y = (screenSize.height - frameSize.height) / 2;
setLocation(x, y);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source=e.getSource();
if(source==Connexion || source==mdp){
try {
con = DriverManager.getConnection("jdbc:postgresql://localhost/centrale",login.getText(),String.copyValueOf(mdp.getPassword()));
JOptionPane.showMessageDialog(null, "Authentification réussie");
dispose();
new Chargement("banque.jpg", 12000);
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null,
"Login ou mot de passe Incorrect ",
"Connexion Erreur",
JOptionPane.ERROR_MESSAGE);
}
}
}
} |
Partager