We would like to process actions and events within the applet, but to do so, we must trap them in some location within the hierarchy where we know they will be seen and then direct them to the applet. This can be done in a number of ways, but one economical way is to override theFrame
class, trap them there, and then send them to our overriden methods in the applet.In the code, below, we override the
Frame
method and use it to instantiate ourouterBox
object.MyFrame outerBox = new MyFrame ( this ); // ************************ MyFrame Class ************************ class MyFrame extends Frame { Applet source; MyFrame ( Applet a ) { super ( ); source = a; } // end constructor public boolean action ( Event event, Object object ) { if ( event.target instanceof MenuItem ) { return source.action ( event, object ); } // end if return false; } // end action public boolean handleEvent ( Event event ) { if ( event.target instanceof Scrollbar ) { return source.handleEvent ( event ); } // end if return super.handleEvent ( event ); } // end handleEvent } // end MyFrame
We can now put all of the pieces together, which we do in the next step.