?
Solved

Controlling Parent Applet from Opened Application

Posted on 1999-07-14
4
Medium Priority
?
217 Views
Last Modified: 2013-11-23
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!
0
Comment
Question by:mh149
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
heyhey_ earned 400 total points
ID: 1246055
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
 

Author Comment

by:mh149
ID: 1246056
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
 
LVL 16

Expert Comment

by:heyhey_
ID: 1246057
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
 

Author Comment

by:mh149
ID: 1246058
You are awesome - thanks a lot.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question