Login Through Enter Button in java swing.
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
type=jComboBox1.getSelectedItem().toString();
if(type=="ADMIN")
{
try
{
String cn=jTextField1.getText();
String pass=jPasswordField1.getText();
String type1=jComboBox1.getSelectedItem().toString();
if(cn.equals(""))
{
JOptionPane.showMessageDialog(null,"Pls Enter ur Name and Password");
}
else if(pass.equals(""))
{
JOptionPane.showMessageDialog(null,"Pls Enter ur Name and Password");
}
else
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");
java.sql.PreparedStatement pst=con.prepareStatement("select name,password from register where name=? and password=? and type='1'");
pst.setString(1,cn);
pst.setString(2,pass);
ResultSet rs=pst.executeQuery();
if(rs.next())
{
close();
Suppliment c=new Suppliment(type);
c.setVisible(true);
con.close();
pst.close();
}
else
{
JOptionPane.showMessageDialog(null,"Error!!!");
}
}
}
catch(Exception e)
{
System.out.println(e);
}
jTextField1.setText("");
jPasswordField1.setText("");
}
else if(type=="USER")
{
try
{
String cn=jTextField1.getText();
String pass=jPasswordField1.getText();
String type1=jComboBox1.getSelectedItem().toString();
if(cn.equals(""))
{
JOptionPane.showMessageDialog(null,"Pls Enter ur Name and Password");
}
else if(pass.equals(""))
{
JOptionPane.showMessageDialog(null,"Pls Enter ur Name and Password");
}
else
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");
java.sql.PreparedStatement pst=con.prepareStatement("select name,password from register where name=? and password=? and type='0'");
pst.setString(1,cn);
pst.setString(2,pass);
ResultSet rs=pst.executeQuery();
if(rs.next())
{
close();
Suppliment c=new Suppliment(type);
c.setVisible(true);
con.close();
pst.close();
}
else
{
JOptionPane.showMessageDialog(null,"Error!!!");
}
}
}
catch(Exception e)
{
System.out.println(e);
}
jTextField1.setText("");
jPasswordField1.setText("");
}
}