You are on page 1of 21

import java.awt.

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

public class Form112 extends Frame implements ActionListener,WindowListener

Connection con;
String str="";
int a[]=new int[100];
int[] pv1=new int[50];
int i=0,j=0;

Random rnumber=new Random();

TextField tx1=new TextField(20);


/* TextField tx2=new TextField(20);*/
TextField tx3=new TextField(20);

Button login_button=new Button("Login");


Button reset_button=new Button("Reset");

Label lb1=new Label("User Name ");

/* Label lb2=new Label("Enter Password (Using Above Figure) ");*/

Label lb3=new Label("Enter position values in your password figure");

/* Button b1=new Button(Integer.toString(rnumber.nextInt(99)+1));


Button b2=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b3=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b4=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b5=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b6=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b7=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b8=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b9=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b10=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b11=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b12=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b13=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b14=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b15=new Button(Integer.toString(rnumber.nextInt(99)+1));
Button b16=new Button(Integer.toString(rnumber.nextInt(99)+1)); */

Button ba=new Button("A");

Button bb=new Button("B");


Button bc=new Button("C");
Button bd=new Button("D");
Button be=new Button("E");
Button bf=new Button("F");
Button bg=new Button("G");
Button bh=new Button("H");
Button bi=new Button("I");
Button bj=new Button("J");
Button bk=new Button("K");
Button bl=new Button("L");
Button bm=new Button("M");
Button bn=new Button("N");
Button bo=new Button("O");
Button bp=new Button("P");

public Form112()
{

// tx2.setEchoChar('*');
tx3.setEchoChar('*');

setLayout(new FlowLayout(FlowLayout.CENTER));

Panel p1=new Panel();


Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();
Panel p5=new Panel();
Panel p6=new Panel();

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);

//---------DATABASE Connection ---------------------------------------------------------

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:krishna2");

catch(Exception e)
{
System.out.println(e);
}

//--------------------------------------------------------------------------------------

/*----------------------Event Handling--------------*/

public void actionPerformed(ActionEvent ae)

{
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()))
{

JOptionPane.showMessageDialog(f1, "Login Success");

//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);
}
}

public void windowClosing(WindowEvent we)


{
System.exit(0);
}

public void windowClosed(WindowEvent we)


{
System.exit(0);
}

public void windowOpened(WindowEvent we)


{

public void windowActivated(WindowEvent we)


{

public void windowDeactivated(WindowEvent we)


{

public void windowIconified(WindowEvent we)


{

public void windowDeiconified(WindowEvent we)


{

/*-------------------------------------------------------*/

public static void main(String args[])


{

Form112 rf=new Form112();

rf.setTitle("User Login Form");


rf.setSize(350,550);
rf.setVisible(true);

You might also like