Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Applet -Applet communication prb

 
Greenhorn
Posts: 19
  • 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
 
Greenhorn
Posts: 15
  • 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
  • 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 am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic