mh149
asked on
Controlling Parent Applet from Opened Application
I have opened an application from an applet, that provides a list of choices and when the user selects one and clicks the appropriate button, I need to jump to the URL associated with the choice. I had it working in the application but Applets evidently open web pages with
getAppletContext().showDoc ument("www.mysite.com");
or something similar. How would I have the application tell the applet to open that site?
Thanks as always!
getAppletContext().showDoc
or something similar. How would I have the application tell the applet to open that site?
Thanks as always!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
replace this
parentApplet.getAppletCont ext().show Document (User_URL);
with
LoaderApplet.parentApplet. getAppletC ontext().s howDocumen t (User_URL);
parentApplet is public static field of LoaderApplet
so you can use it from everywhere with
LoaderApplet.parentApplet
(and you've already initialized it to point to the current applet instance)
parentApplet.getAppletCont
with
LoaderApplet.parentApplet.
parentApplet is public static field of LoaderApplet
so you can use it from everywhere with
LoaderApplet.parentApplet
(and you've already initialized it to point to the current applet instance)
ASKER
You are awesome - thanks a lot.
ASKER
import java.applet.*;
import java.awt.*;
public class LoaderApplet extends Applet
{
public static LoaderApplet parentApplet;
public void init()
{
parentApplet = this;
Search Search_App = new Search();
}
}
Now in my Search Class, when I try and access parentApplet, I get this
import org.gjt.mm.mysql.Driver.*;
import org.gjt.mm.mysql.Connectio
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
import java.net.URL;
public class Search extends Frame implements MouseListener, WindowListener, ActionListener, ItemListener
{
.
.
.
private void goto_URL(String strURL)
{
parentApplet.getAppletCont
}
.
.
.
}
It gives me the error:
Undefined name 'parentApplet'
and when I run the the applet I get:
java.lang.NoSuchMethodErro
at LoaderApplet.init (LoaderApplet.java:11)
at com/ms/applet/AppletPanel.
at com/ms/applet/AppletPanel.
at com/ms/applet/AppletPanel.
at com/ms/applet/AppletPanel.
at java/lang/Thread.run (Thread.java)
Am I supposed to link to the LoaderApplet class somehow?