Link to home
Start Free TrialLog in
Avatar of mh149
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().showDocument("www.mysite.com");

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

Thanks as always!
ASKER CERTIFIED SOLUTION
Avatar of heyhey_
heyhey_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mh149
mh149

ASKER

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?

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)
Avatar of mh149

ASKER

You are awesome - thanks a lot.