[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Frame to parent command

Posted on 1997-03-07
1
Medium Priority
?
241 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
[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
1 Comment
 
LVL 1

Accepted Solution

by:
tatti earned 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.
Suggested Courses

649 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