Solved

Frame to parent command

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 55
countAbc challenge 9 49
create a gui in perl 3 45
maven project error 5 21
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

705 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

20 Experts available now in Live!

Get 1:1 Help Now