Espace login et mot de passe

208893 Messages postés 55 Date d'inscription mercredi 14 avril 2010 Statut Membre Dernière intervention 21 décembre 2010 - 2 août 2010 à 14:03
safanouri Messages postés 1 Date d'inscription mardi 8 février 2011 Statut Membre Dernière intervention 21 février 2011 - 21 févr. 2011 à 22:51
j'ai un erreur dans mon code je ne trouve pas une solution voila mon code
**********************************************************************
//LoginForm.java
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.UnknownHostException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;


import javax.imageio.IIOException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.border.Border;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class LoginForm extends JFrame {

// Variables declaration
private JLabel jLabel1;
private JLabel jLabel2,jLabel3;
private JTextField jTextField1;
private JComboBox l3=null;
private JPasswordField jPasswordField1;
private JButton jButton1;
private JPanel contentPane;
boolean loop = false;
// End of variables declaration

public LoginForm() {
super();
create();
this.setVisible(true);
}

private void create() {
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jTextField1 = new JTextField();
jPasswordField1 = new JPasswordField();
l3=new JComboBox();
l3.addItem("Administrateur");
l3.addItem("Non administrateur");
jButton1 = new JButton();
contentPane = (JPanel)this.getContentPane();

//
// jLabel1
//
jLabel1.setHorizontalAlignment(SwingConstants.LEFT);
jLabel1.setForeground(new Color(0, 0, 255));
jLabel1.setText("Login :");
//
// jLabel2
//
jLabel2.setHorizontalAlignment(SwingConstants.LEFT);
jLabel2.setForeground(new Color(0, 0, 255));
jLabel2.setText("Mot de passe :");
//

// jLabel2
//
jLabel3.setHorizontalAlignment(SwingConstants.LEFT);
jLabel3.setForeground(new Color(0, 0, 255));
jLabel3.setText("Etat :");
//

// jTextField1
//
jTextField1.setForeground(new Color(0, 0, 255));
jTextField1.setSelectedTextColor(new Color(0, 0, 255));
jTextField1.setToolTipText("Entrer votre login");

//
// jPasswordField1
//
jPasswordField1.setForeground(new Color(0, 0, 255));
jPasswordField1.setToolTipText("Entrer votre mot de passe");

//


// jTextField1
//
l3.setForeground(new Color(0, 0, 255));
l3.setSelectedItem(new Color(0, 0, 255));
l3.setToolTipText("login");

//


// jButton1
//
jButton1.setBackground(new Color(204, 204, 204));
jButton1.setForeground(new Color(0, 0, 255));
jButton1.setText("OK");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
actionPerformed(e);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

});

//
// contentPane
//
contentPane.setLayout(null);
contentPane.setBorder(BorderFactory.createEtchedBorder());
contentPane.setBackground(new Color(204, 204, 204));
addComponent(contentPane, jLabel1, 5,10,106,18);
addComponent(contentPane, jLabel2, 5,47,97,18);
addComponent(contentPane, jLabel3, 5,77,90,18);
addComponent(contentPane, jTextField1, 110,10,183,22);
addComponent(contentPane, jPasswordField1, 110,45,183,22);

addComponent(contentPane, l3, 110,75,183,22);

addComponent(contentPane, jButton1, 150,100,25,28);

//
// login
//
this.setTitle("Espace d'authentification");
this.setLocation(new Point(76, 182));
this.setSize(new Dimension(345, 251));
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setResizable(false);
} //end of create()

/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height) {
c.setBounds(x,y,width,height);
container.add(c);
} //end of addComponent()

private void jLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jLoginActionPerformed
boolean connected = false;
try {
new ConnectDB("jdbc:mysql://localhost:3306/eracontacttt","com.mysql.jdbc.Driver","root");
connected = true;

} catch(Exception ee) {
ee.toString(); }
if (connected) {
try
{

String sql1="SELECT password FROM membre WHERE username = '" + jTextField1.getText()+"' and rôle='"+l3.getSelectedItem().toString()+"'" ;
//System.out.println(sql1);
Statement statement = ConnectDB.getConnection().createStatement();
ResultSet resultat =(ResultSet) statement.executeQuery(sql1);

String password=null ;

while(resultat.next()) {
password =resultat.getString(1);
//System.out.println(password);
// System.out.println(jPassword.getText());
}
if (password.equals(jPasswordField1.getText()))
{
this.setVisible(false);
if(l3.getSelectedItem().toString().equals("Administrateur"))
{

new ZFenetre().setVisible(true);
}
else
{
if(l3.getSelectedItem().toString().equals("non administrateur"))
{
new Ofenetre().setVisible(true);

}


}

}
else
{
// error.message_erreur("Verifier vos paramètre ");
jPasswordField1.setText("");
jTextField1.setText("");
}
}
catch(SQLException e)
{
// error.message_erreur(e.getMessage());
}



}


// TODO add your handling code here:
}//GEN-LAST:event_jLoginActionPerformed


public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
//ZFenetre zFen = new ZFenetre();
liste_ouvrier lf = new liste_ouvrier();

add_ouv add = new add_ouv();

Liste_formation form = new Liste_formation();
// ajout_formation ajou = new ajout_formation();
Liste_process proc = new Liste_process();
ajout_process ajoutt = new ajout_process();
//liste_planifier plan = new liste_planifier();
// planifier plani = new planifier();

try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} //end of try

catch (Exception ex) {
//System.out.println("Failed loading L&F: ");
//System.out.println(ex);
} //end of catch

new LoginForm();
}; //end of main()

} //end of LoginForm
***************************************************************************merci d'avance

2 réponses

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 131
2 août 2010 à 14:15
Salut,

Et quel est le problème au juste ?

Tu aurai perdu bien moins de temps si tu avais déjà répondu à ma question ici.
______________________________________

AVANT de poster votre message, veuillez lire, comprendre, et appliquer notre réglement
0
safanouri Messages postés 1 Date d'inscription mardi 8 février 2011 Statut Membre Dernière intervention 21 février 2011
21 févr. 2011 à 22:51
salut à tous;
mon problème comment enregister le mot de passe et le login dans le base de données.
merci d'avance
0
Rejoignez-nous