File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CALLING RAUKAUTAM SANDEEP,ANGELA

 
asheet anand
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
angela asked a ? for applet to applet communication on 28th nov,
2000 and sandeep you answered the ?.
thanks alot it was a great help to me.IT WORKS FINE ALSO.
but i have a problem,in your example you have both the
applets defined in one HTML file.what I did is ,i defined the
to applets in two different HTML files.then from the 1st applet
i am calling the 2nd applet by showDocument() method.
but the value is not coming in the second applet.
please help me everybody.
CODE FOR 1ST APPLET
-------------------
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class appl1 extends Applet implements ActionListener
{
TextField t1,t2;
Button b1,b2;
AppletContext ac;
txtctrl txt;
public void init()
{
t1=new TextField(10);
t2=new TextField(10);
b1=new Button("Add");
b2=new Button("Exit");
add(t1);
add(t2);
add(b1);
add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
ac=getAppletContext();
txt=(txtctrl)ac.getApplet("textboxapplet");
}
public void actionPerformed(ActionEvent ae)
{
int txt1,txt2,txt3;
if(ae.getSource().equals(b1))
{
String f1,f2,f3;
f1=(t1.getText());
f2=(t2.getText());
f3=f1+f2;
txt.tf.setText(f3);
URL u=getCodeBase();
try{
ac.showDocument(new URL(u+"go1.html"));
}catch(Exception e){}

showStatus("You have clicked the Add button in the applet window.");
}
else if(ae.getSource().equals(b2))
{
t1.setText("hi");
}
}
}
CODE FOR 2ND APPLET
---------------------
import java.awt.*;
import java.applet.*;
public class txtctrl extends Applet
{TextField tf;

public void init()
{tf=new TextField(10);
add(tf);
tf.setEnabled(false);
}
}
HTML FILE FOR 1ST APPLET.
-------------------------
<html>
<BODY>
<APPLET CODE="appl1.class" name="sampleapplet" width=250 height=100>
</APPLET>
</BODY>
</HTML>

HTML FILE FOR 2ND APPLET
---------------------------
<html>
<BODY>
<APPLET CODE="txtctrl.class" name="textboxapplet" width=250 height=100></APPLET>
</BODY>
</HTML>
all the files are in the same directory.
PLEASE HELP AS I AM REALLY STUCK UPPPPP.
THANKS IN ADVANCE,
asheet
 
Nitin Shivaram
Ranch Hand
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi asheet,
Well thats the limitation of AppletContext.getApplet(s), it returns only the applets which are on the same html page.
There is a workaround to this, and this is what you have to do.
Each of the applets you are using should have a static field in it which stores a reference to itself.
Say CallingApplet has to call CalledApplet for some functionality.
CalledApplet stores a reference to itself in its init method.

Now the calling applet CallingApplet will get the reference of the CalledApplet by doing this..

The above workaround works because applets having the same codebase will share the same runtime environment, and likewise the static variables.
cheerio !!

------------------
Nitin S
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic