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
 

"A Little of Everything"
Vol. 2, Issue 7, p. 50

	

Listing 1: AppletFrame.java
 
import java.awt.Frame; 
import java.applet.Applet; 
import java.awt.MenuItem; 
import java.awt.Event; 

public class 
AppletFrame 
extends Frame 
{ 
 Applet      myApplet; 

 public 
 AppletFrame( Applet myApplet ) 
 { 
  super(); 
  setApplet( myApplet ); 
 } 

 public 
 AppletFrame( Applet myApplet, String title ) 
 { 
  super( title ); 
  setApplet( myApplet ); 
 } 

 public void 
 setApplet( Applet myApplet ) 
 { 
  this.myApplet = myApplet; 
 } 

 public Applet 
 getApplet( Applet myApplet ) 
 { 
  return( myApplet ); 
 } 

 public boolean 
 action( Event e, Object arg ) 
 { 
  if ( myApplet != null ) 
   return( myApplet.handleEvent( e ) ); 

  return( false ); 
 } 
} 
  

Listing 2: FrameMenu.java
 
import java.applet.*; 
import java.awt.*; 

public class  
FrameMenu  
extends Applet 
{ 
 AppletFrame  myFrame = new AppletFrame( this ); 
 Menu   fileMenu, helpMenu; 
  

 public  
 FrameMenu() 
 { 
 } 

 public void  
 init() 
 { 
     resize(320, 240); 

        MenuBar mb = new MenuBar(); 

        fileMenu = new Menu( "File", true ); 
        fileMenu.add( new MenuItem( "Open" ) ); 
        fileMenu.addSeparator(); 
        fileMenu.add( new MenuItem( "Exit" ) ); 
  mb.add( fileMenu ); 

        helpMenu = new Menu( "Help" ); 
        helpMenu.add( new MenuItem( "About..." ) ); 
  helpMenu.getItem( 0 ).disable(); 
        mb.add( helpMenu ); 
  mb.setHelpMenu( helpMenu ); 

  myFrame.setMenuBar( mb ); 
  myFrame.show(); 
 } 

 public boolean  
 handleEvent( Event e ) 
 { 
  System.out.println( e.toString() ); 
  return( super.handleEvent( e ) ); 
 } 

}


 

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.