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().showDocument("www.mysite.com");

or something similar.  How would I have the application tell the applet to open that site?

Thanks as always!
mh149Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

heyhey_Commented:
make a public static variable inside your applet class

public class MyApplet extends Applet
{
public static MyApplet theApplet;
public void inti()
{
  theApplet = this;
  ....
}
....
}

now you can use theApplet.getAppletContext().showDocument()

1. note that there are several other solutions (your code just needs a reference to the applet and there are a lot of ways to to set this reference).
2. note that this code won't work very well when user has loaded more than one instance of your applet.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mh149Author Commented:
Here is my loader applet class:

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.Connection.*;
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.getAppletContext().showDocument (User_URL);
      }
     .
     .
     .
}

It gives me the error:
   Undefined name 'parentApplet'
and when I run the the applet I get:

java.lang.NoSuchMethodError: Search: method <init>()V not found
      at LoaderApplet.init (LoaderApplet.java:11)
      at com/ms/applet/AppletPanel.securedCall0 (AppletPanel.java)
      at com/ms/applet/AppletPanel.securedCall (AppletPanel.java)
      at com/ms/applet/AppletPanel.processSentEvent (AppletPanel.java)
      at com/ms/applet/AppletPanel.run (AppletPanel.java)
      at java/lang/Thread.run (Thread.java)


Am I supposed to link to the LoaderApplet class somehow?

0
heyhey_Commented:
replace this
parentApplet.getAppletContext().showDocument (User_URL);

with
LoaderApplet.parentApplet.getAppletContext().showDocument (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)
0
mh149Author Commented:
You are awesome - thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.