home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / AppletFrame.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  3.6 KB  |  112 lines

  1. // $Header: z:/admin/metro_examples/java/demo/GraphicsTest/rcs/AppletFrame.java 1.1 1997/02/06 00:30:03 IPGIntel-2 Exp $ 
  2. /*
  3.  * @(#)AppletFrame.java    1.3 96/12/06
  4.  *
  5.  * Copyright (c) 1994-1996 Sun Microsystems, Inc. All Rights Reserved.
  6.  *
  7.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  8.  * modify and redistribute this software in source and binary code form,
  9.  * provided that i) this copyright notice and license appear on all copies of
  10.  * the software; and ii) Licensee does not utilize the software in a manner
  11.  * which is disparaging to Sun.
  12.  *
  13.  * This software is provided "AS IS," without a warranty of any kind. ALL
  14.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  15.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  16.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  17.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  18.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  19.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  20.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  21.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  22.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  23.  * POSSIBILITY OF SUCH DAMAGES.
  24.  *
  25.  * This software is not designed or intended for use in on-line control of
  26.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  27.  * the design, construction, operation or maintenance of any nuclear
  28.  * facility. Licensee represents and warrants that it will not use or
  29.  * redistribute the Software for such purposes.
  30.  */
  31.  
  32. import java.awt.Frame;
  33. import java.awt.Event;
  34. import java.awt.Dimension;
  35. import java.applet.Applet;
  36.  
  37. // Applet to Application Frame window
  38. class AppletFrame extends Frame
  39. {
  40.  
  41.     public static void startApplet(String className, 
  42.                                    String title, 
  43.                                    String args[])
  44.     {
  45.        // local variables
  46.        Applet a;
  47.        Dimension appletSize;
  48.  
  49.        try 
  50.        {
  51.           // create an instance of your applet class
  52.           a = (Applet) Class.forName(className).newInstance();
  53.        }
  54.        catch (ClassNotFoundException e) { return; }
  55.        catch (InstantiationException e) { return; }
  56.        catch (IllegalAccessException e) { return; }
  57.  
  58.        // initialize the applet
  59.        a.init();
  60.        a.start();
  61.   
  62.        // create new application frame window
  63.        AppletFrame f = new AppletFrame(title);
  64.   
  65.        // add applet to frame window
  66.        f.add("Center", a);
  67.   
  68.        // resize frame window to fit applet
  69.        // assumes that the applet sets its own size
  70.        // otherwise, you should set a specific size here.
  71.        appletSize =  a.size();
  72.        f.pack();
  73.        f.resize(appletSize);  
  74.  
  75.        // show the window
  76.        f.show();
  77.   
  78.     }  // end startApplet()
  79.   
  80.   
  81.     // constructor needed to pass window title to class Frame
  82.     public AppletFrame(String name)
  83.     {
  84.        // call java.awt.Frame(String) constructor
  85.        super(name);
  86.     }
  87.  
  88.     // needed to allow window close
  89.     public boolean handleEvent(Event e)
  90.     {
  91.        // Window Destroy event
  92.        if (e.id == Event.WINDOW_DESTROY)
  93.        {
  94.           // exit the program
  95.           System.exit(0);
  96.           return true;
  97.        }
  98.        
  99.        // it's good form to let the super class look at any 
  100.        // unhandled events
  101.        return super.handleEvent(e);
  102.  
  103.     }  // end handleEvent()
  104.  
  105. }   // end class AppletFrame
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.