Hey!there pro, I need ur kind help to solve my problem.Here is my coding.Now the problem is there no error when I compile the coding but I find some task does'nt work but I have implement it in my coding(Example connection to database and the user name and password validation).What the problem actually.
Code:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import java.net.*;
public class MyLogin extends Frame implements ActionListener
{
//Boolean id=false;
JButton ok,can,next;
JFrame jf;
TextField username;
TextField password;
static ResultSet result;
static Connection con;
static Statement stat;
public MyLogin()
{
super("Welcome");
jf=new JFrame("Welcome");
setLayout(new FlowLayout());
MyWinListener mywindow=new MyWinListener();
addWindowListener(mywindow);
username = new TextField(15);
password = new TextField(15);
password.setEchoChar('*');
add(new JLabel("User :"));
add(username);
add(new JLabel("Password :"));
add(password);
addOKCancelNextPanel();
createFrame();
pack();
setVisible(true);
blist obj=new blist();
}
void addOKCancelNextPanel()
{
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
createButtons( p );
add( p );
}
void createButtons(JPanel p)
{
p.add(ok = new JButton("OK"));
ok.addActionListener(this);
p.add(can = new JButton("Cancel"));
can.addActionListener(this);
p.add(next = new JButton("Next"));
next.addActionListener(this);
}
void createFrame()
{
Dimension d = getToolkit().getScreenSize();
setLocation(d.width/4,d.height/3);
}
class blist implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==ok)
{
String uid=new String(username.getText());
String pwd=new String(password.getText());
if(uid.equals("Ram")&& pwd.equals("kumar"))
JOptionPane.showMessageDialog(jf,new String("Your password is correct"));
else
JOptionPane.showMessageDialog(jf,new String("Your password is not correct"));
username.setText("");
password.setText("");
}//end of the command
else if(ae.getSource()==can)
{
username.setText("");
password.setText("");
JOptionPane.showMessageDialog(jf,new String("Thank you"));
}
}
}
class MyWinListener implements WindowListener
{
public void windowClosing(WindowEvent w)
{
System.exit(0);
}
public void windowClosed(WindowEvent w)
{
}
public void windowOpened(WindowEvent w)
{
}
public void windowIconified(WindowEvent w)
{
}
public void windowDeiconified(WindowEvent w)
{
}
public void windowActivated(WindowEvent w)
{
}
public void windowDeactivated(WindowEvent w)
{
}
}
public static void main(String args[])
{
MyLogin obj=new MyLogin();
try
{
Class.forName("sun.jdbc.odbc.jdbcodbcDriver");
Connection con;
con=DriverManager.getConnection("jdbc:odbc:kumar","","");
stat=con.createStatement();
result=stat.executeQuery("Select * from Javadetail");
result.next();
}
catch(Exception e)
{
System.out.println("Error.."+e);
}
obj.showRecord(result);
}
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource()==can)
{
setVisible(false);
}
else if(evt.getSource()==next)
{
try
{
result.next();
}
catch(Exception e)
{}
showRecord(result);
}
}
public void showRecord(ResultSet result)
{
try
{
password.setText(result.getString(2));
username.setText(result.getString(2));
}
catch(Exception e)
{}
}
}