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
|
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.swing.SwingUtilities;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Rectangle;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.SystemColor;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class david extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
JPanel jContentPane = null;
private JPanel jPanel = null;
private JTextField jTextField = null;
private JPasswordField jPasswordField = null;
private JButton jButton = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JPanel getJPanel() {
if (jPanel == null) {
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(100, 115, 92, 30));
jLabel1.setText("Mot de passe :");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(100, 66, 95, 30));
jLabel.setText("Nom utilisateur :");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBounds(new Rectangle(8, 5, 481, 476));
jPanel.setBackground(new Color(0, 138, 255));
jPanel.add(getJTextField(), null);
jPanel.add(getJPasswordField(), null);
jPanel.add(getJButton(), null);
jPanel.add(jLabel, null);
jPanel.add(jLabel1, null);
}
return jPanel;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(235, 66, 148, 30));
}
return jTextField;
}
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(235, 115, 148, 30));
jPasswordField.setFont(new Font("Dialog", Font.PLAIN, 18));
}
return jPasswordField;
}
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(269, 174, 98, 26));
jButton.setForeground(SystemColor.desktop);
jButton.setText("Connection");
jButton.setBackground(Color.orange);
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String nom = jTextField.getText();
String passe1 = jPasswordField.getText().trim();
String prenom="";
String passeword="";
try {
Connection connection = null;
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
String serverName = "10.133.0.25";
String portNumber = "1521";
String sid = "fin";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber +":" + sid;
String username = "DEVRTO";
String password = "DEVRTO";
connection = DriverManager.getConnection(url, username, password);
Statement instruction = connection.createStatement();
String sql = " select utilisateur, mot_passe from utilisateur where utilisateur ='"+nom+"' and mot_passe ='"+passe1+"' ";
ResultSet resultat = instruction.executeQuery(sql);
HttpServletRequest request = null;
HttpSession session = request.getSession(true);
while (resultat.next()){
prenom= resultat.getString("utilisateur");
passeword= resultat.getString("mot_passe");
session.setAttribute("uname",prenom);
session.setAttribute("agence",passeword);
}
if ((prenom.equals(nom))&& (passeword.equals(passe1))) {
menu a =new menu();
a.setVisible(true);
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a.setResizable (false);
a.setLocationRelativeTo(null);
setVisible(false);
}
else
{
JOptionPane ddd1 = new JOptionPane();
ddd1.showMessageDialog(david.this, "mot passe ou user erronée ","Erreur",JOptionPane.INFORMATION_MESSAGE);
}
}
catch (Exception ex) {
System.out.println("jjjjjjjjjjj "+ex.getMessage());
ex.printStackTrace() ;
}
}
});
}
return jButton;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
david thisClass = new david();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
thisClass.setResizable (false);
thisClass.setLocationRelativeTo(null);
}
});
}
public david() {
super();
initialize();
}
private void initialize() {
this.setSize(700, 405);
this.setBackground(Color.orange);
this.setContentPane(getJContentPane());
this.setTitle("TRC-EXL-RTO-INF");
this.setIconImage(new ImageIcon("src/image/sonatrach.png").getImage());
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBackground(new Color(0, 138, 255));
jContentPane.add(getJPanel(), null);
}
return jContentPane;
}
} |
Partager