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
| import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class BDD_Connexion extends JDialog implements WindowListener,ActionListener,KeyListener
{
AgenceFrame frame;
private JTextField texteUser;
private JPasswordField textePassword;
private JButton bOk;
private JButton bCancel;
private String user;
char[] pass;
boolean ok=false;
public BDD_Connexion(AgenceFrame frame2)
{
//Connexion BDD et Agence Frame
frame=frame2;
//Design de la BDD
JPanel pan1 = new JPanel();
pan1.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc=Grille(0,0,1,1,GridBagConstraints.NONE,GridBagConstraints.LINE_START,new Insets(10, 15, 0, 0));
JLabel Lb_pseudo = new JLabel (" Pseudo :");
pan1.add(Lb_pseudo, gbc);
// TexteField Pseudo
gbc=Grille(1,0,GridBagConstraints.REMAINDER,1,GridBagConstraints.NONE,GridBagConstraints.LINE_START,new Insets(10, 15, 0, 0));
texteUser=new JTextField(10);
pan1.add(texteUser,gbc);
//Password
gbc=Grille(0,1,1,1,GridBagConstraints.NONE,GridBagConstraints.LINE_START,new Insets(10, 15, 0, 0));
JLabel Lb_password = new JLabel (" Mot de passe :");
pan1.add(Lb_password,gbc);
//TextField Password
gbc=Grille(1,1,GridBagConstraints.REMAINDER,1,GridBagConstraints.NONE,GridBagConstraints.LINE_START,new Insets(10, 15, 0, 0));
textePassword=new JPasswordField(10);
textePassword.setEchoChar('*');
pan1.add(textePassword,gbc);
//Bouton OK
gbc=Grille(0,2,1,1,GridBagConstraints.HORIZONTAL,GridBagConstraints.BASELINE_TRAILING,new Insets(10, 15, 0, -10));
bOk=new JButton ("Ok");
pan1.add(bOk,gbc);
//Bouton CANCEL
gbc=Grille(1,2,GridBagConstraints.REMAINDER,GridBagConstraints.REMAINDER,GridBagConstraints.HORIZONTAL,GridBagConstraints.BASELINE_TRAILING,new Insets(10, 15, 0, 5));
bCancel=new JButton("Cancel");
pan1.add(bCancel,gbc);
this.add(pan1);
addWindowListener(this);
textePassword.addKeyListener(this);
texteUser.addKeyListener(this);
bOk.addActionListener(this);
bCancel.addActionListener(this);
this.pack();
this.setModal(true);
this.setTitle("Connexion");
this.setLocationRelativeTo(null);
this.setSize(270, 150);
this.setVisible(true);
this.setResizable(false);
}
private GridBagConstraints Grille(int x, int y, int w, int h, int f, int a, Insets I)
{
GridBagConstraints gbc1 = new GridBagConstraints();
gbc1.gridx = x;
gbc1.gridy = y;
gbc1.gridwidth = w;
gbc1.gridheight = h;
gbc1.fill = f;
gbc1.anchor = a;
gbc1.insets = I;
return gbc1;
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==bOk)
{
setUser(texteUser.getText());
setPassword(textePassword.getPassword());
ok=true;
dispose();
}
if (e.getSource()==bCancel)
{
setUser("");
setPassword(null);
ok=false;
dispose();
}
}
public void keyPressed(KeyEvent e)
{
//System.out.println(e.getKeyCode());
if (e.getKeyCode()==KeyEvent.VK_ENTER)
{
setUser(texteUser.getText());
setPassword(textePassword.getPassword());
ok=true;
dispose();
}
if (e.getKeyCode()==KeyEvent.VK_ESCAPE)
{
setUser("");
setPassword(null);
ok=true;
dispose();
}
}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {}
public void windowClosing(WindowEvent e) {dispose();}
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void setUser(String s) {user=s;}
public String getUser() {return user;}
public void setPassword(char[] string) {pass=string;}
public char[] getPassword() {return pass;}
public boolean getReponse() {return ok;}
} |
Partager