HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"Using Applets in Java Applications"
Vol.1, Issue 2, P.28


Listing 1: Loading and Instantiating the Applet

Applet applet = null;
try {
	Class c = Class.forName( appletName );
	applet = c.newInstance();
catch( Exception e ) {
	// handle exception here

Listing 2: Running the Applet Example Code

applet.hide();	// Hide the applet initally
applet.init();	// Initialize the applet
applet.start();	// Begin the execution of the applet
applet.resize( new Dimension( width , height ) );
applet.show();	// Show the applet
validate();	// Validate the layout manager

Listing 3: Overriding the handleEvent() Function

public boolean handleEvent( Event e ) {
	switch ( e.id ) {
		case Event.WINDOW_ICONIFY:
		// Other events are handled here...

Listing 4: Application Level Caching

public Image getImage( URL location ) {
	Image img = cache.get(location);
	if ( img != null ) return img;
	img = loadImageFromURL(location);
	cache.put( location , img );

	return img;

Listing 5: Passing Parameters from the Application to Embedded Applets

public class Application extends Frame implements AppletStub {
	private Hashtable params = new Hashtable();

	public String getParameter( String key ) {
		return params.get(key);

	public static void main( String args[] ) {
		for ( int I=0; I< args.length; I++ ) {
				    getArgValue(args[i]) );
	// Some other code


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.