Wednesday, 1 August 2012

Java Program for implement Inter Applet communication In The Distributed System

Aim
Write a java program to implement Inter applet communication in the Distributed System
Program

 FirstApplet.java 
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;

/*<applet code="FirstApplet.class"  width=300 height=300 name="first">
</applet>*/
/*<applet code="SecondApplet.class" width=300 height=300 name="second"></applet>*/

public class FirstApplet extends JApplet implements ActionListener
{
JTextArea ta;
JButton b1;
JTextField txt1;

public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout(FlowLayout.LEFT));
txt1=new JTextField(20);
b1=new JButton("send");
ta=new JTextArea(20,30);
ta.setEditable(false);
b1.addActionListener(this);
c.add(txt1);
c.add(b1);
c.add(ta);
}
public void actionPerformed(ActionEvent ae)
{
JApplet second=(JApplet)getAppletContext().getApplet("second");
((SecondApplet)second).ta.append("first>"+txt1.getText()+"\n");
ta.append("first>"+txt1.getText()+"\n");
txt1.setText("");
}
}



------------------------------------------------------------------------------------------------------------------
SecondApplet.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SecondApplet extends JApplet implements ActionListener
{
JTextArea ta;
JButton b1;
JTextField txt1;

public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout(FlowLayout.LEFT));
txt1=new JTextField(20);
b1=new JButton("send");
ta=new JTextArea(20,30);
ta.setEditable(false);
b1.addActionListener(this);
c.add(txt1);
c.add(b1);
c.add(ta);
}
public void actionPerformed(ActionEvent ae)
{
JApplet first=(JApplet)getAppletContext().getApplet("first");
((FirstApplet)first).ta.append("second>"+txt1.getText()+"\n");
ta.append("second>"+txt1.getText()+"\n");
txt1.setText("");
}
}

No comments:

Post a Comment