Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet -Applet communication prb

 
Rajeev Kashyap
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to call a method of one applet(AppA) in another applet(AppB)but on Java Console it is giving null pointer exception. Following is code.

import java.applet.*;
import java.awt.*;

public class AppA extends Applet
{
Button b1;

public void init()
{
b1=new Button("A");
add(b1);
}

public String say()
{
return "hello";
}
}

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class AppB extends Applet implements ActionListener
{
Button b1;
TextField t1;

public void init()
{
b1=new Button("Click");
b1.addActionListener(this);
t1=new TextField(10);
add(b1);
add(t1);
}

public void actionPerformed(ActionEvent e)
{
AppA r=(AppA)getAppletContext().getApplet("AppA");
t1.setText(r.say());
}
}

<html>
<body>
Applet Comm Ex
<applet code="AppA" width="400" height="100" name="app1"> </applet>
<hr width=2>
<br>
<applet code="AppB" width="400" height="100" name="app2"> </applet>
<br>
</body>
</html>

Please let me know solution
 
Maybach Smith
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,

Hope this is useful to you.
http://www.javaworld.com/javaworld/javatips/jw-javatip101.html
 
Rajeev Kashyap
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem was wrongly described by me.
The actual problem is suppose in web page there is frame containing two html pages say htmA.html and htmB.html. In htmA.html there is one applet say AppletA and in htmB.html there are two applets say AppletB and AppletC.
Now invoking the method of AppletA is not possible through AppletB but any method method of AppletC can be invoked through AppletB.

Is the AppletContext is limited to single html web page or for whole web page? If the appletcontext is limited to html page then what is the solution to invoke applet's method of other html page in same web page.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic