Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

Applet mode in a window

By: sriharshachilakapati on Aug 26th, 2012  |  syntax: Java  |  size: 1.10 KB  |  views: 127  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class GApplet extends JApplet {
  2.  
  3.     /**
  4.      *
  5.      */
  6.     private static final long serialVersionUID = 1994280929713148311L;
  7.  
  8.     String gmname = "";
  9.     Class<?> gmClass = null;
  10.    
  11.     Game game = null;
  12.    
  13.     /**
  14.      * Construct an applet with a game.
  15.      * @param gmname The name of the game class with package name
  16.      */
  17.     public GApplet(String gmname) {
  18.         this.gmname = gmname;
  19.     }
  20.  
  21.     /**
  22.      * Initializes the applet mode
  23.      */
  24.     public void init(){
  25.         Global.WEB_MODE = true;
  26.         try {
  27.             gmClass = getClass().getClassLoader().loadClass(gmname);
  28.             game = (Game)gmClass.newInstance();
  29.         } catch (ClassNotFoundException e) {
  30.             System.err.println("Error finding class : " + gmname);
  31.             e.printStackTrace();
  32.         } catch (InstantiationException e) {
  33.             e.printStackTrace();
  34.         } catch (IllegalAccessException e) {
  35.             e.printStackTrace();
  36.         }
  37.     }
  38.    
  39.     public void showGame(){
  40.         if (!Game.isRunning()){
  41.             GWindow.setup(game);
  42.         }
  43.     }
  44.  
  45. }