Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning variables from a frame

Status
Not open for further replies.

modalman

Programmer
Feb 14, 2001
156
GB
Could anyone tell me how I can return values from a java frame back to an applet on a web page. Many thanks in advance.
 
Use a callback reference to the Applet that is passed in to the CTOR of the Frame then have the Frame use the callback reference to set a value on the applet via an accessor method you have provided.
 
Thanks meadandale
This callback ref thats passed to the Frame constructor. Would it be the Applet object as in:

public class myframe extends Frame{

public myframe(Applet myapplet, etc

Thanks again

 
Correct. Then to create the frame in the applet:

Frame myframe = new myframe(this);

There are many ways to implement the coupling. You can make the Frame class a member class of the applet and then it has direct access to the other member variables of the applet or you can create an accessor method to the variable(s) you want the frame to be able to change and then pass a reference to your specific type of applet to the frame on instantiation like above. The frame then uses this callback ref to call the accessor methods and interact with the frame. There are pluses and minuses to each approach. It just depends on how extensible you want things to be. The tighter you couple the relationship between the two classes, the harder it is to change later. Sometimes it is easier to create some interfaces which include specific functionality then implement these interfaces in your two classes. This makes it easier to change things later.

If you need more concrete examples, let me know.
meadandale@yahoo.com

Regards,

Charles

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top