Solved

Frame to parent command

Posted on 1997-03-07
1
232 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now