Advertisement
sriharshachilakapati

Applet mode in a window

Aug 26th, 2012
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement