here is the following code
in java applet..
//this is one applet which has to be opened when button is clicked...
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Order_info extends Applet implements ItemListener
{
private Label l,l1,l2;
private TextField t=new TextField();
private Choice list;
String s,selection;
public void init()
{
this.setLayout(new BorderLayout(10,10));
Panel p1=new Panel(new GridLayout(3,5,7,4));
l2=new Label(" ORDER INFORMATION ");
l2.setFont(new Font("Courier",Font.BOLD,48));
p1.add(l2);
add(p1,"North");
Panel p=new Panel(new GridLayout(3,3,4,4));
l=new Label("ITEM");
p.add(l);
list = new Choice();
list.addItem("LCD TV");
list.addItem("FRIDGE");
list.addItem("AIRCONDITIONER");
list.addItemListener(this);
p.add(list);
l1=new Label("PRICE");
p.add(l1);
p.add(t);
add(p,"Center");
}
public void itemStateChanged(ItemEvent e)
{selection=list.getSelectedItem();
if(selection.equals("LCD TV"))
{
s="15000";
t.setText(s);
}
else if(selection.equals("FRIDGE"))
{s="20000";
t.setText(s);
}
else if(selection.equals("AIRCONDITIONER"))
{
s="25000";
t.setText(s);
}
}
public void paint(Graphics g)
{
g.drawRect(0,0,this.getSize().width-1,this.getSize().height-1);
}
}
//here is another applet where button b6 is clicked..
import java.io.*;
import java.math.*;
import java.security.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public final class MsgDigestApp extends java.applet.Applet implements ActionListener
{
private Button b0,b1,b2,b3,b4,b5,b6;
private TextArea message=new TextArea("ENTER PURCHASE INFORMATION");
private TextArea message1=new TextArea("ENTER ORDER INFORMATION");
private TextArea a=new TextArea();
private TextArea a1=new TextArea();
private TextField digest=new TextField();
private TextField digest1=new TextField();
private TextField digest2=new TextField();
private TextField t=new TextField();
private TextField n=new TextField();
private TextField phi=new TextField();
private TextField pub=new TextField();
private TextField dec_msg=new TextField();
private TextField en_msg=new TextField();
private MessageDigest sha;
private Label l,l1,s1,s2,s3,s4,s5,s6;
private Label la1,la2,la3,la4,la5,la6,la7;
public void init()
{
this.setLayout(new BorderLayout(10,10));
Panel p1=new Panel();
l=new Label("purchase info");
p1.add(l);
p1.add(message);
//l1=new Label("Order info");
//p1.add(l1);
b6=new Button("ORDER INFO");// this button is clicked to open another applet
b6.addActionListener(this);
p1.add(b6);
//p1.add(message1);
p1.add(message1);
add(p1,"North");
Panel p2 = new Panel(new GridLayout(4,2, 5, 5));
s1=new Label("hash1");
p2.add(s1);
p2.add(digest);
s2=new Label("hash2");
p2.add(s2);
p2.add(digest1);
s3=new Label("concat");
p2.add(s3);
p2.add(t);
s4=new Label("hash resultant");
p2.add(s4);
p2.add(digest2);
add(p2,"South");
Panel p=new Panel(new GridLayout(2,1,4,4));
b0=new Button("Clear text");
b0.addActionListener(this);
p.add(b0);
b1=new Button("Hash");
b1.addActionListener(this);
p.add(b1);
add(p,"West");
setAlgo("sha-1");
Panel p5=new Panel(new GridLayout(10,1,7,7));
la1=new Label("enter p");
p5.add(la1);
p5.add(a);
la2=new Label("enter q");
p5.add(la2);
p5.add(a1);
s5=new Label("Value(n)");
p5.add(s5);
p5.add(n);
la3=new Label("phi");
p5.add(la3);
p5.add(phi);
la4=new Label("Public Key: e");
p5.add(la4);
p5.add(pub);
s6=new Label("Encrypted msg");
p5.add(s6);
p5.add(en_msg);
la7=new Label("Decrypted msg");
p5.add(la7);
p5.add(dec_msg);
add(p5,"Center");
Panel p6=new Panel(new GridLayout(2,1,4,4));
b2=new Button("Cal N");
b2.addActionListener(this);
p6.add(b2);
b3=new Button("Encrypt");
b3.addActionListener(this);
p6.add(b3);
b4=new Button("Decrypt");
b4.addActionListener(this);
p6.add(b4);
add(p6,"East");
}
public void itemStateChanged(ItemEvent evt)
{ if (evt.getStateChange() == ItemEvent.SELECTED)
setAlgo((String)evt.getItem());
}
private void setAlgo(String alg)
{ try
{ sha = MessageDigest.getInstance(alg);
} catch(NoSuchAlgorithmException e)
{ digest.setText("" + e);
digest1.setText("" + e);
digest2.setText(""+e);
}
}
public void actionPerformed(ActionEvent evt)
{
String arg=evt.getActionCommand();
if(arg.equals("ORDER INFO"))//to open new applet..what should be the right code
{
getAppletContext().showDocument(order);
}
else if(arg.equals("Hash"))
{
String m=message.getText();
String m1=message1.getText();
String m2=t.getText();
computeDigest(m.getBytes());
computeDigest1(m1.getBytes());
con();
computeDigest2(m2.getBytes());
}
else if(arg.equals("Cal N"))
{
cal_n();
choose_e();
}
else if(arg.equals("Encrypt"))
{
en();
}
else if(arg.equals("Decrypt"))
{
dec();
}
else if(arg.equals("Clear text"))
{
message.setText("");
digest.setText("");
message1.setText("");
digest1.setText("");
t.setText("");
digest2.setText("");
n.setText("");
phi.setText("");
pub.setText("");
a.setText("");
a1.setText("");
en_msg.setText("");
dec_msg.setText("");
}
}
private void computeDigest(byte[] b)
{
sha.reset();
sha.update(b);
byte[] hash1=sha.digest();
String d="";
String e="";
int usbyte=0;
for(int i=0;i<hash1.length;i++)
{
usbyte=hash1[i]&0xFF;
if(usbyte<16)
d+="0"+Integer.toHexString(usbyte);
else
d+=Integer.toHexString(usbyte);
}
e=d.toUpperCase();
digest.setText(""+e);
}
private void computeDigest1(byte[] b)
{
sha.reset();
sha.update(b);
byte[] hash2=sha.digest();
String d="";
String f="";
int usbyte=0;
for(int i=0;i<hash2.length;i++)
{
usbyte=hash2[i]&0xFF;
if(usbyte<16)
d+="0"+Integer.toHexString(usbyte);
else
d+=Integer.toHexString(usbyte);
}
f=d.toUpperCase();
digest1.setText(""+f);
}
private void computeDigest2(byte[] b)
{
sha.reset();
sha.update(b);
byte[] hash1=sha.digest();
String d="";
String e="";
int usbyte=0;
for(int i=0;i<hash1.length;i++)
{
usbyte=hash1[i]&0xFF;
if(usbyte<16)
d+="0"+Integer.toHexString(usbyte);
else
d+=Integer.toHexString(usbyte);
}
e=d.toUpperCase();
digest2.setText(""+e);
}
private void con()
{
String str,x,y;
x=digest.getText();
y=digest1.getText();
str=x+y;
t.setText(""+str);
}
private void cal_n()
{
String mul1,mul2,mul0,mul;
int x,y,x1,y1,mul3,mul4;
mul1=a.getText();
mul2=a1.getText();
x=Integer.parseInt(mul1);
y=Integer.parseInt(mul2);
mul3=x*y;
mul=String.valueOf(mul3);
n.setText(""+mul);
x1=Integer.parseInt(mul1)-1;
y1=Integer.parseInt(mul2)-1;
mul4=x1*y1;
mul0=String.valueOf(mul4);
phi.setText(""+mul0);
}
private void choose_e()
{
String n1=phi.getText();
BigInteger n2=new BigInteger(n1);
String n3=pub.getText();
BigInteger n4=new BigInteger(n3);
while( n4.gcd( n2 ).compareTo( BigInteger.ONE ) != 0 )
{
n4 = n4.add( BigInteger.ONE );
pub.setText(n4.toString());
}
}
private void en()
{
String n1=n.getText();
BigInteger n2= new BigInteger(n1);
String n3=pub.getText();
BigInteger n4= new BigInteger(n3);
String hexmsg=digest2.getText();
BigInteger v= new BigInteger(hexmsg,16);
BigInteger c = v.modPow( n4, n2 );
String c2=String.valueOf(v);
en_msg.setText(""+c2);
}
private void dec()
{String n1=n.getText();
BigInteger n2= new BigInteger(n1);
String c1=en_msg.getText();
BigInteger c2=new BigInteger(c1);
String n3=pub.getText();
BigInteger n4= new BigInteger(n3);
String n5=phi.getText();
BigInteger n6= new BigInteger(n5);
BigInteger d =n4.modInverse( n6 );
BigInteger m=c2.modPow(d,n2);
dec_msg.setText(""+m.toString(16));
}
public void paint(Graphics g)
{
setBackground(Color.black);
g.setColor(Color.blue);
g.drawRect(0,0,this.getSize().width-1, this.getSize().height-1) ;
}
}