Professional Documents
Culture Documents
*;
import java.sql.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
Connection con;
String str="";
int a[]=new int[100];
int[] pv1=new int[50];
int i=0,j=0;
public Form112()
{
// tx2.setEchoChar('*');
tx3.setEchoChar('*');
setLayout(new FlowLayout(FlowLayout.CENTER));
p1.setLayout(new GridLayout(4,4,1,1));
p4.setLayout(new GridLayout(4,4,1,1));
p5.setLayout(new GridLayout(4,4,1,1));
p6.setLayout(new GridLayout(4,4,1,1));
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
p3.setLayout(new GridLayout(1,2,15,5));
/*------------------------------------------------b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
ba.addActionListener(this);
bb.addActionListener(this);
bc.addActionListener(this);
bd.addActionListener(this);
be.addActionListener(this);
bf.addActionListener(this);
bg.addActionListener(this);
bh.addActionListener(this);
bi.addActionListener(this);
bj.addActionListener(this);
bk.addActionListener(this);
bl.addActionListener(this);
bm.addActionListener(this);
bn.addActionListener(this);
bo.addActionListener(this);
bp.addActionListener(this);
-------------------------------------------------------*/
login_button.addActionListener(this);
reset_button.addActionListener(this);
addWindowListener(this);
p2.add(lb1);
p2.add(tx1);
p5.add(lb3);
p5.add(tx3);
p6.add(ba);
p6.add(bb);
p6.add(bc);
p6.add(bd);
p6.add(be);
p6.add(bf);
p6.add(bg);
p6.add(bh);
p6.add(bi);
p6.add(bj);
p6.add(bk);
p6.add(bl);
p6.add(bm);
p6.add(bn);
p6.add(bo);
p6.add(bp);
/*
p4.add(lb2);
p4.add(tx2); */
/*
p1.add(b1);
p1.add(b2);
p1.add(b3);
p1.add(b4);
p1.add(b5);
p1.add(b6);
p1.add(b7);
p1.add(b8);
p1.add(b9);
p1.add(b10);
p1.add(b11);
p1.add(b12);
p1.add(b13);
p1.add(b14);
p1.add(b15);
p1.add(b16); */
p3.add(login_button);
p3.add(reset_button);
add(p2);
add(p6);
add(p5);
add(p1);
add(p4);
add(p3);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:krishna2");
catch(Exception e)
{
System.out.println(e);
}
//--------------------------------------------------------------------------------------
/*----------------------Event Handling--------------*/
{
String tname=tx1.getText();
String pos_value=tx3.getText();
String[] pv=pos_value.split("");
int j=0;
System.out.println("\npv values");
System.out.println("no.of values = "+pv.length);
for(int i=1;i<pv.length;i++)
System.out.println(" "+pv[i]+" ");
for(int i=1;i<pv.length;i++)
{
if(pv[i].equals("A"))
pv1[i]=11;
else if(pv[i].equals("B"))
pv1[i]=12;
else if(pv[i].equals("C"))
pv1[i]=13;
else if(pv[i].equals("D"))
pv1[i]=14;
else if(pv[i].equals("E"))
pv1[i]=21;
else if(pv[i].equals("F"))
pv1[i]=22;
else if(pv[i].equals("G"))
pv1[i]=23;
else if(pv[i].equals("H"))
pv1[i]=24;
else if(pv[i].equals("I"))
pv1[i]=31;
else if(pv[i].equals("J"))
pv1[i]=32;
else if(pv[i].equals("K"))
pv1[i]=33;
else if(pv[i].equals("L"))
pv1[i]=34;
else if(pv[i].equals("M"))
pv1[i]=41;
else if(pv[i].equals("N"))
pv1[i]=42;
else if(pv[i].equals("O"))
pv1[i]=43;
else if(pv[i].equals("P"))
pv1[i]=44;
System.out.println("\npv1 values");
for(int i=1;i<pv.length;i++)
System .out.println(" "+pv1[i]+" ");
String s=ae.getActionCommand();
System.out.println(s+" "+tname);
String s1="",s2="";
String x="";
Frame f1=new Frame();
try {
if(s.equals("Login"))
{
String q="select * from "+tname;
System.out.println(q);
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(q);
int count=0;
i=0;
while(rs.next())
{
a[i++]=rs.getInt(1);
//a[i++]=rs.getInt(2);
count++;
}
rs.close();
System.out.println("\na values");
for(int i=0;i<count;i++)
System .out.println(" "+a[i]+" ");
//--------------------------------------------------------------------------------------------------------------------------
if(pv.length-1 == count)
{
int temp=0;j=1;
for(int i=0;i<count;i++,j++)
{
if(pv1[j] == a[i])
temp++;
System.out.println(pv1[j]+"
: "+a[i]);
}
System.out.println("temp = "+temp);
if(temp==count)
JOptionPane.showMessageDialog(f1, "Login Success");
else
JOptionPane.showMessageDialog(f1, "Login Fail");
}
else
JOptionPane.showMessageDialog(f1, "Login Fail");
/*for(int i=1;i<=pv1.length;i++)
{
for(;j<a.length;j++)
{
if(pv1[i]==a[j])
{
System.out.println("Position equal");
j++;
break;
}
}
if(j>=a.length)
{
JOptionPane.showMessageDialog(f1, "Login Fail");
break;
}
}*/
/*for(int m=0;m<i;m++)
{
x=pv[m];
System.out.println(x+" ");
if(x.equals("A"))
{
s1=s1+(b1.getLabel());
else if(x.equals("B"))
s1=s1+(b2.getLabel());
else if(x.equals("C"))
s1=s1+(b3.getLabel());
else if(x.equals("D"))
s1=s1+(b4.getLabel());
else if(x.equals("E"))
s1=s1+(b5.getLabel());
else if(x.equals("F"))
s1=s1+(b6.getLabel());
else if(x.equals("G"))
{
s2=b7.getLabel();
//System.out.println(s2);
s1=s1+s2;
//System.out.println(b7.getLabel());
//System.out.println(s1);
}
else if(x.equals("H"))
s1=s1+(b8.getLabel());
else if(x.equals("I"))
s1=s1+(b9.getLabel());
else if(x.equals("J"))
s1=s1+(b10.getLabel());
else if(x.equals("K"))
s1=s1+(b11.getLabel());
else if(x.equals("L"))
s1=s1+(b12.getLabel());
else if(x.equals("M"))
s1=s1+(b13.getLabel());
else if(x.equals("N"))
s1=s1+(b14.getLabel());
else if(x.equals("O"))
s1=s1+(b15.getLabel());
else if(x.equals("P"))
s1=s1+(b16.getLabel());
}*/
/*System.out.println(s1);
if(s1.equals(tx2.getText()))
{
//System.out.println("Login Success");
}
else
{
s1="";
JOptionPane.showMessageDialog(f1, "Login Fail.");
}*/
}
else if(s.equals("Reset"))
{
Form112 rf=new Form112();
rf.setTitle("User Login Form");
rf.setSize(350,350);
rf.setVisible(true);
}
catch(Exception e)
{
System.out.println(e);
}
}
/*-------------------------------------------------------*/