How i convert a java code into Jsp code...please help me
843840Apr 17 2008 — edited Apr 17 2008import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
import java.applet.*;
public class data1 extends JPanel implements ActionListener
{
int response;
JLabel j1,j2,j3,j4;
JRadioButton jr1,jr2,jr3,jr4,jr5,jr6,jr7,jr8;
JButton b1,b2,b3;
JTextField t1;
String d_lic;
boolean i[];
//i=new boolean[5];
long a[];
int p=11,q=13;
static long x0=1;
static Connection conn;
Statement stmt;
ResultSet rs;
public data1()
{
setLayout(null);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
try
{
conn=DriverManager.getConnection("jdbc:odbc:vote");//,"pgdit29","pgdit29"
stmt=conn.createStatement();
}
catch(SQLException e1)
{
System.out.println(e1.getMessage());
}
j1=new JLabel("Please Select Candidate Press Next");
j1.setBounds(200,15,400,60);
j1.setFont(new Font("Serif",Font.BOLD,20));
j1.setForeground(Color.red);
add(j1);
j2=new JLabel("1.Which Candidate For Indian President?");
j2.setBounds(200,80,400,60);
j2.setFont(new Font("Serif",Font.BOLD,15));
j2.setForeground(Color.blue);
add(j2);
j3 = new JLabel("2.What is your voter_id No:?");
j3.setBounds(200,260,400,60);
j3.setFont(new Font("Serif",Font.BOLD,15));
j3.setForeground(Color.blue);
//add(j3);
jr1 = new JRadioButton("a.Abdul Kalam");
jr1.setBounds(200,120,400,60);
jr1.setForeground(Color.blue);
add(jr1);
jr2 = new JRadioButton("b.Amrtaya sen");
jr2.setBounds(200,160,400,60);
jr2.setForeground(Color.blue);
add(jr2);
jr3 = new JRadioButton("c.Amitabh Bacchan");
jr3.setBounds(200,200,400,60);
jr3.setForeground(Color.blue);
add(jr3);
jr4 = new JRadioButton("d.NarayanMurthy");
jr4.setBounds(200,250,400,60);
jr4.setForeground(Color.blue);
add(jr4);
ButtonGroup bg = new ButtonGroup();
bg.add(jr1);
bg.add(jr2);
bg.add(jr3);
bg.add(jr4);
jr1.addActionListener(this);
jr2.addActionListener(this);
jr3.addActionListener(this);
jr4.addActionListener(this);
t1=new JTextField(20);
t1.setBounds(230,320,150,20);
t1.setForeground(Color.blue);
//add(t1);
b1=new JButton("Exit");
b2=new JButton("<<Back");
b3=new JButton("submit");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b1.setBounds(0,430,120,30);
b2.setBounds(450,430,120,30);
b3.setBounds(560,430,120,30);
add(b1);
add(b2);
add(b3);
j4=new JLabel(new ImageIcon("evm.jpg"));
add(j4);
j4.setBounds(5,30,200,80);
}
//IMPLEMENTATION OF VOTING SYSTEM
// MODULUS FOR POSITIVE & NEGETIVE NUMBERS
long mod(long a,long b)
{
while(a<0)
{
a=a+b;
}
a=a%b;
return(a);
}
long multiply1(long a,long b,long c)
{
long a1=a,b1=1,p=1;
while(b1<=b)
{
p=a1;
a1=a1+a1;
a1=mod(a1,c);
b1=b1+b1;
}
return(p);
}
// MULTIPLY LARGE VALUES BY REPEATEDLY USING ADDITION
long multiply2(long a,long b,long c)
{
long b1;
long k[];
k=new long [10000];
long p=0;
int k1,i=0;
while(b!=0)
{
i++;
k=multiply1(a,b,c);
b1=1;
while(b1<=b)
{
b1=b1+b1;
}
b1=b1/2;
b=b-b1;
}
for(k1=1;k1<=i;k1++)
{
p=p+k[k1];
p=mod(p,c);
}
//System.out.println(p);
return(p);
}
// GREATEST COMMON DIVISER
long gcd(long a,long b)
{
long r1=1;
while(r1!=0)
{
r1=mod(a,b);
a=b;
b=r1;
}
return(a);
}
// MODULER INVERSE
long modu_inverse(long a,long b)
{
long q0,x0,x1,x2,r1,k;
x0=0;
x1=1;
r1=mod(b,a);
k=b;
while(r1!=0)
{
q0=b/a;
x2=(x0-(x1*q0));
x2=mod(x2,k);
x0=x1;
x1=x2;
b=a;
a=r1;
r1=mod(b,a);
}
return(x1);
}
/* RANDOM NUMBER GENERATION
long RanNum()
{
long time1 ;
long n,p1;
n=p*q;
p1=n*n;
time1 = System.currentTimeMillis();
time1=time1/10;
if(gcd(time1,p1)!=1)
RanNum();
return(time1);
}*/
long RanNum()
{
long a=102,k,p1,m12=1999,c=0,n;
n=p*q;
k=(a*x0+c);
x0=mod(k,m12);
p1=n*n;
if(gcd(x0,p1)!=1)
RanNum();
return(x0);
}
// CALCULATION OF C=G^M*Y^N MOD N^2
long encryption(long m)
{
long c1,c2,a,k,b;
long i,c,p2,p3,g,n;
n=p*q;
c2=n*n;
//G=N+1 ALWAYS WORKS
g=n+1;
p2=g;
for(i=1;i<m;i++)
{
p2=multiply2(p2,g,c2);
}
//System.out.println(p2);
a=mod(p2,c2);
if(m==0)
{
a=1;
}
k=RanNum();
//cout<<"\tr_n="<<k;
//getch();
p3=k;
for(i=1;i<n;i++)
{
p3=multiply2(p3,k,c2);
}
b=mod(p3,c2);
c1=multiply2(a,b,c2);
c=mod(c1,c2);
return(c);
}
/* // CALCULATION OF RANDOM NUMBER
long RanNumCal(long ct)
{
long phi,n,alpha;
long i,p1,rd1;
n=p*q;
phi=(p-1)*(q-1);
alpha=modu_inverse(n,phi);
p1=ct;
for(i=1;i<alpha;i++)
{
p1=multiply2(p1,ct,n);
}
rd1=mod(p1,n);
//cout<<"\tr_a_d="<<rd1;
//getch();
return(rd1);
}
*/
void save()
{ i=new boolean[5];
int j;
a=new long[5];
d_lic=t1.getText();
i[1]=jr1.isSelected();
i[2]=jr2.isSelected();
i[3]=jr3.isSelected();
i[4]=jr4.isSelected();
for( j=1;j<=4;j++)
{
if(i[j]==true)
{
a[j]=encryption(1);
}
else
{
a[j]=encryption(0);
}
}
for( j=1;j<=4;j++)
{
System.out.println(a[j]);
}
try
{
stmt.executeUpdate("insert into vote values(" a[1]"," a[2]","+a[3]+"," a[4]")");//,'"+t1.getText()+"'
System.out.println("Submit Successful");
stmt.close();
conn.close();
System.out.println("Dialog");
JOptionPane.showMessageDialog(null,"you have done well" , "information",JOptionPane.INFORMATION_MESSAGE);
}
catch(SQLException se)
{
System.out.println(se.getMessage());
}
}
public static void close1()
{
try
{
conn.close();
}
catch(Exception aa)
{
System.out.println("close connection "+aa);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b3)
{
System.out.println("Confirm ");
response=JOptionPane.showConfirmDialog(null,"Do you want to confirm your vote ?","Searching",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(response==JOptionPane.YES_NO_OPTION)
{
System.out.println("yes clicked");
save();
}
}
if(e.getSource()==b1)
{
System.exit(0);
}
if(e.getSource()==b2)
{
//dispose();
}
}
public static void main(String args[])
{
JFrame frm=new JFrame("VOTE");
data1 r2=new data1();
frm.setContentPane(r2);
frm.setSize(700,550);
frm.setVisible(true);
WindowListener w1=new WindowAdapter()
{
public void windowClosing(WindowEvent ev)
{
System.exit(0);
}
};
frm.addWindowListener(w1);
}
}