[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Frame to parent command

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
brecht
Asked:
brecht
1 Solution
 
tattiCommented:
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now