how to call an applet from another applet

hi

i have 2 applets each has separately its own init(),paint() methods.they basically read the data from 2 data files and draw the figures.

What i want to do is since the 2 applets use the same data files i want to run any one applet depending upon the data in the data files.how to combine them.

this is the html file

<html>

<head><title>IFM</title>

</head>

<body>

<applet code=IfmComp.class width=1500 height=2500>

<param name=IDataFileName value="ProppedBeam.dat">

<param name=ODataFileName value="ProppedBeam.out">

<param name=Title value="Three Bar Truss">

</applet>

<applet code=Beam.class width=1500 height=2500>

<param name=IDataFileName value="ProppedBeam.dat">

<param name=ODataFileName value="ProppedBeam.out">

<param name=Title value="Three Bar Truss">

</applet>

</body>

</html>

The IfmComp.java is

public class IfmComp {

public void init() {

input = getParameter("IDataFileName");

is = new URL(getDocumentBase(),input);

InputStream fileIn = is.openStream();

int bytes = fileIn.read(buffer,0,100000);

str = new String(buffer,0,bytes);

String str2;

if( str2.equals("IFMBM") {

Beam b =new Beam(); } // if i do in this way both the appets r displayed but i want to display only the beam applet when the string is equal to IFMBM.

}

public void paint() {

g.drawLine(x1,y1,x2,y2);

}

}

// simllary Beam.java has the same methods and reading data.

so how to

pls help me i need to do this project as soon as possible.

[1810 byte] By [kumary] at [2008-2-11]
# 1

If you don't still have the solution you can try this.

In the first applet :

private SecondApplet sa = null;

sa = (SecondApplet)getAppletContext().getApplet("name");

where name is the name, of the second applet, that you have put in the parameter "name" of the applet tag.

After this you can call all the method of the second applet by typing : sa.methodName()

Hope that helps.

David.

dWalczynski at 2007-7-2 > top of java,Security,Signed Applets...
# 2

Hi

Thanks for ur reply

it doesnt work out actually.the 2 applets r running simulatneoulsy but i want to run only one applet whether the Beam or IfmComp at a time.

pls tell how to do it.

bcos the html page contains 2 applets it displays the 2 applets but i want only 1 applet

kumary at 2007-7-2 > top of java,Security,Signed Applets...
# 3
i tried ur method but it doesnt work when the string is not equal to IFMB .i mean when it is not equal it should display he IfmComp applet for me.
kumary at 2007-7-2 > top of java,Security,Signed Applets...
# 4
i want to display only one applet beam or ifmcomp .let me know
kumary at 2007-7-2 > top of java,Security,Signed Applets...
# 5
Hi, Sorry when I replied I've don't understood your problem and sorry but I don't know how to do what you want to.
dWalczynski at 2007-7-2 > top of java,Security,Signed Applets...