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
| package Distributeur;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.ResultSet;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class authentification implements ActionListener {
private JFrame f;
private JPanel p;
private JButton b1;
private JButton b2,b3;
private JLabel lab1;
private JLabel lab2;
private JLabel lab3;
private JRadioButton rd1;
private JRadioButton rd2;
private JTextField text1,text2;
public authentification(){
f=new JFrame();
f.setTitle("Connexion");
f.setVisible(true);
f.setSize(580, 380);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
p=new JPanel(new GridBagLayout());
p.setBackground(Color.cyan);
Font policeL = new Font("Times New Roman", Font.BOLD, 16);
Font policeC= new Font("Arial", Font.BOLD, 18);
Border thickBorder = new LineBorder(Color.black, 3);
GridBagConstraints c=new GridBagConstraints();
b1=new JButton("Connexion");
b2=new JButton("Inscription");
b3=new JButton("Exit");
lab1=new JLabel("Type of User");
lab2=new JLabel("Login");
lab3=new JLabel("Passe Word");
rd1=new JRadioButton("Customer");
rd2=new JRadioButton("Manager");
text1=new JTextField();
text2= new JTextField();
b1.setFont(policeC);
b2.setFont(policeC);
b3.setFont(policeC);
lab1.setFont(policeL);
lab2.setFont(policeL);
lab3.setFont(policeL);
lab1.setForeground(Color.BLUE);
lab2.setForeground(Color.BLUE);
lab3.setForeground(Color.BLUE);
rd1.setFont(policeL);
rd2.setFont(policeL);
rd1.setBackground(Color.cyan);
rd2.setBackground(Color.cyan);
ButtonGroup group = new ButtonGroup();
group.add(rd1);
group.add(rd2);
b1.addActionListener(this);
c.gridx=0;
c.gridy=0;
c.insets=new Insets(0,40,0,0);
p.add(lab1,c);
c.insets=new Insets(0,0,0,0);
c.gridx=1;
c.gridy=1;
p.add(rd1,c);
p.add(rd2);
c.gridx=0;
c.gridy=2;
c.insets=new Insets(40,40,40,40);
p.add(lab2,c);
c.insets=new Insets(0,0,0,0);
c.gridx=1;
c.gridy=2;
c.weightx = 4.0;
c.fill = GridBagConstraints.HORIZONTAL;
p.add(text1,c);
c.weightx = 4.0;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx=0;
c.gridy=4;
text1.setPreferredSize(new Dimension(100, 30));
c.insets=new Insets(0,80,0,0);
p.add(lab3,c);
c.insets=new Insets(0,0,0,0);
c.gridx=1;
c.gridy=4;
p.add(text2,c);
c.gridx=0;
c.gridy=5;
text2.setPreferredSize(new Dimension(150, 30));
p.add(b1,c);
c.gridx=1;
c.gridy=5;
c.insets=new Insets(40,40,40,40);
p.add(b2,c);
c.gridx=2;
c.gridy=5;
c.insets=new Insets(0,0,0,0);
p.add(b3,c);
b1.setBorder(thickBorder);
b1.setPreferredSize(new Dimension(100, 50));
b2.setBorder(thickBorder);
b2.setPreferredSize(new Dimension(100, 50));
b2.setEnabled(false);
b3.setBorder(thickBorder);
b3.setPreferredSize(new Dimension(100, 50));
if(rd1.isSelected()){
b2.setEnabled(true);
}
f.add(p,BorderLayout.CENTER);
}
public static void main(String []args){
new creation();
}
@Override
public void actionPerformed(ActionEvent arg0) {
String log,mot;
if (rd1.isSelected()){
log=text1.getText();
mot=text2.getText();
System.out.println(log);
System.out.println(mot);
Connection laConnection;
Statement transmission;
ResultSet leResultat=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
laConnection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/application?useSSL=false","boutheina","30071986");
transmission= (Statement) laConnection.createStatement();
leResultat = transmission.executeQuery("select * from client where idClient =1");
// leResultat = transmission.executeQuery("select * from produit");
while(leResultat.next()){
System.out.println("login: "+leResultat.getString("login"));
//System.out.println("")
//System.out.println("Id_prod: "+leResultat.getInt("Id_Prod")+"designation: "
//+leResultat.getString("designation")+"quantite: "+leResultat.getInt("quantite")+" Prix: "+leResultat.getFloat("prix"));
System.out.println("Vous avez le droit d'entrer");
}
}
catch
(Exception e)
{
System.out.print("impossible de se connecter à la base");
}
}
}} |
Partager