Solved

Frame to parent command

Posted on 1997-03-07
1
234 Views
Last Modified: 2009-12-16
If I have an applet that spawns an external frame and I want
that frame to call a method of the applet, what do I do?

(In particular, I'm working on a navigation tool for my site.  The applet will reside in one frame (in the HTML sense of frame) and the pages of the site in another.  The applet will spawn an external window (Java frame) that has buttons that can be pressed or somesuch, so that the other frame(HTML) will display a new document at the touch of a button in the free floating Java frame.  So I have a method in the applet that will "getAppletContext()" and "showDocument()".  I want the window (Java frame) that the applet spawns, to contain buttons such that when pressed the frame will cause the method to be called with some URL as a parameter.  (For instance, if the user presses the button "Home", the "changePage(URL u)" method that I've written will be called, with the URL of the first page of my website as a parameter.))
0
Comment
Question by:brecht
1 Comment
 
LVL 1

Accepted Solution

by:
tatti earned 100 total points
ID: 1218922
I've done the same thing, and the problem isn't really too big. All you need to do is derive a class from class Frame and use a constructor that passes the reference to the Applet to it. The reference is then stored as an instance variable and when the Frame then reacts to a button, it can do something like

myApplet->getAppletContext()->showDocument(URLOfButton1);

Here's a sketch of the frame...

class MyFrame extends Frame {
  Applet myApplet;
  public MyFrame(String title, Applet applet) {
    super(title);
    myApplet=applet;
    // Create your GUI here...
  }
  public boolean action(Event evt, Object arg) {
    // Put your button handling code here...
  }
}

In addition to this, all you need to do is create the MyFrame from the applet with the correct parameters

MyFrame frame=new MyFrame("Remote controller",this);

and make sure you don't implement the traditional public void stop(void) method, because it is called when the browser moves to another page, and will thus shut down your applet. Just make sure you have a method of shutting it down yourself (like a button or a menu entry that will do the trick). It will have to call the applet so it can remove itself - just disposing() of the Frame isn't enough.

Hope this helps.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
use lov values 2 71
hibernate jars 4 57
Java class and jar 3 41
junit example issue 2 22
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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

685 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