R
rajesh
here is my coding can any one help me to communicate b\w applet and
jsp,...
"appleeet.jsp"
------------
<%@ page language="java" %>
<jsplugin type="applet" code="sample2.class"
codebase="/appleet/sample2.java" jreversion="1.2" width="160"
height="150" >
<jsp:fallback>
Plugin tag OBJECT or EMBED not supported by browser.
</jsp:fallback>
</jsplugin>
"sample2.java" is the java code
-------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class sample2 extends JApplet implements ActionListener
{
JLabel l1,l2,l3,l4,l5;
JTextField t1,t2,t3;
JPasswordField tt1,tt2;
JButton b1,b2,b3;
JPanel p;
Font f;
public void init()
{
Container c=getContentPane();
//c.setLayout(new FlowLayout(0));
c.setBackground(Color.cyan);
f=new Font("Monotype Corsiva",Font.BOLD,16);
//creating panel
p=new JPanel();
p.setLayout(new GridLayout(7,2));
p.setBackground(Color.green);
// p.setFont(f);
p.setLocation(200,200);
//creating components
l1=new JLabel("First name ");l1.setFont(f);
l2=new JLabel("Last name ");l2.setFont(f);
l3=new JLabel("Login id ");l3.setFont(f);
l4=new JLabel("Password");l4.setFont(f);
l5=new JLabel("Confirm password");l5.setFont(f);
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(10);
tt1=new JPasswordField();
tt2=new JPasswordField();
b1=new JButton("Check");b1.addActionListener(this);
b2=new JButton("clear");b2.addActionListener(this);
b3=new JButton("Reset");b3.addActionListener(this);
//adding components to panel
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p.add(l4);
p.add(tt1);
p.add(l5);
p.add(tt2);
p.add(b1);
p.add(b2);
p.add(b3);
//adding panel to container
c.add(p);
}
public void actionPerformed(ActionEvent e)
{
String ss1="";
String s=tt1.getText();
String s1=tt2.getText();
a: if(e.getSource()==b1)
{
if(t1.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the first name", null, JOptionPane.ERROR_MESSAGE );
t1.requestFocus(true);
break a;
}
if(t2.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the last name", null, JOptionPane.ERROR_MESSAGE );
t2.requestFocus(true);
break a;
}
if(t3.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the Login id", null, JOptionPane.ERROR_MESSAGE );
t3.requestFocus(true);
break a;
}
if(tt1.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the password", null, JOptionPane.ERROR_MESSAGE );
tt1.requestFocus(true);
break a;
}
if(tt2.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the confirm password", null, JOptionPane.ERROR_MESSAGE );
tt2.requestFocus(true);
break a;
}
else {
if(s.equals(s1))
{
JOptionPane.showMessageDialog(null,"The entered
password is correct"," Verification",
JOptionPane.INFORMATION_MESSAGE );
}
else
{
JOptionPane.showMessageDialog(null,"Please type the
password correctly"," Verification", JOptionPane.WARNING_MESSAGE );
tt2.setText("");
}
}
}
if(e.getSource()==b3)
{
t1.setText("");t2.setText("");t3.setText("");tt1.setText("");tt2.setText
("");
}
if(e.getSource()==b2)
{
tt2.setText("");
}
}
}
//<applet code=sample2 height=200 width=200></applet>
jsp,...
"appleeet.jsp"
------------
<%@ page language="java" %>
<jsplugin type="applet" code="sample2.class"
codebase="/appleet/sample2.java" jreversion="1.2" width="160"
height="150" >
<jsp:fallback>
Plugin tag OBJECT or EMBED not supported by browser.
</jsp:fallback>
</jsplugin>
"sample2.java" is the java code
-------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class sample2 extends JApplet implements ActionListener
{
JLabel l1,l2,l3,l4,l5;
JTextField t1,t2,t3;
JPasswordField tt1,tt2;
JButton b1,b2,b3;
JPanel p;
Font f;
public void init()
{
Container c=getContentPane();
//c.setLayout(new FlowLayout(0));
c.setBackground(Color.cyan);
f=new Font("Monotype Corsiva",Font.BOLD,16);
//creating panel
p=new JPanel();
p.setLayout(new GridLayout(7,2));
p.setBackground(Color.green);
// p.setFont(f);
p.setLocation(200,200);
//creating components
l1=new JLabel("First name ");l1.setFont(f);
l2=new JLabel("Last name ");l2.setFont(f);
l3=new JLabel("Login id ");l3.setFont(f);
l4=new JLabel("Password");l4.setFont(f);
l5=new JLabel("Confirm password");l5.setFont(f);
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(10);
tt1=new JPasswordField();
tt2=new JPasswordField();
b1=new JButton("Check");b1.addActionListener(this);
b2=new JButton("clear");b2.addActionListener(this);
b3=new JButton("Reset");b3.addActionListener(this);
//adding components to panel
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p.add(l4);
p.add(tt1);
p.add(l5);
p.add(tt2);
p.add(b1);
p.add(b2);
p.add(b3);
//adding panel to container
c.add(p);
}
public void actionPerformed(ActionEvent e)
{
String ss1="";
String s=tt1.getText();
String s1=tt2.getText();
a: if(e.getSource()==b1)
{
if(t1.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the first name", null, JOptionPane.ERROR_MESSAGE );
t1.requestFocus(true);
break a;
}
if(t2.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the last name", null, JOptionPane.ERROR_MESSAGE );
t2.requestFocus(true);
break a;
}
if(t3.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the Login id", null, JOptionPane.ERROR_MESSAGE );
t3.requestFocus(true);
break a;
}
if(tt1.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the password", null, JOptionPane.ERROR_MESSAGE );
tt1.requestFocus(true);
break a;
}
if(tt2.getText().equals(ss1))
{
JOptionPane.showMessageDialog(null,"Please
enter the confirm password", null, JOptionPane.ERROR_MESSAGE );
tt2.requestFocus(true);
break a;
}
else {
if(s.equals(s1))
{
JOptionPane.showMessageDialog(null,"The entered
password is correct"," Verification",
JOptionPane.INFORMATION_MESSAGE );
}
else
{
JOptionPane.showMessageDialog(null,"Please type the
password correctly"," Verification", JOptionPane.WARNING_MESSAGE );
tt2.setText("");
}
}
}
if(e.getSource()==b3)
{
t1.setText("");t2.setText("");t3.setText("");tt1.setText("");tt2.setText
("");
}
if(e.getSource()==b2)
{
tt2.setText("");
}
}
}
//<applet code=sample2 height=200 width=200></applet>