/Users/lyon/j4p/src/ip/gui/frames/AppletFrame.java

1    package ip.gui.frames; 
2     
3    import java.applet.Applet; 
4    import java.awt.*; 
5     
6     
7    // Applet to Application Frame window AppletFrame 
8     
9    public class AppletFrame extends ClosableFrame { 
10    
11       public static void startApplet(Applet a) { 
12           Dimension appletSize; 
13           // initialize the applet 
14           // create new application frame window 
15           AppletFrame f = new AppletFrame("Applet Frame"); 
16    
17           // add applet to frame window 
18           f.add("Center", a); 
19    
20    
21           // resize frame window to fit applet 
22           // assumes that the applet sets its own size 
23           // otherwise, you should set a specific size here. 
24    
25           f.pack(); 
26           a.init(); 
27           a.start(); 
28           appletSize = a.getSize(); 
29    
30           f.setSize(appletSize); 
31           f.show(); 
32    
33           // show the window 
34    
35    
36       } 
37    
38       public static void startApplet(String className) { 
39           String args[] = {""}; 
40           startApplet( 
41                   className, 
42                   className, 
43                   args); 
44       } 
45    
46       public static void startApplet(String className, 
47                                      String title, String args[]) { 
48           Applet a; 
49           Dimension appletSize; 
50    
51           try { 
52               // create an instance of your applet class 
53               a = (Applet) Class.forName(className).newInstance(); 
54           } catch (ClassNotFoundException e) { 
55               System.out.println("ClassNotFoundException in AppletFrame"); 
56               return; 
57           } catch (InstantiationException e) { 
58               System.out.println("InstantiationException in AppletFrame"); 
59               return; 
60           } catch (IllegalAccessException e) { 
61               System.out.println("IllegalAccessException in AppletFrame"); 
62               return; 
63           } 
64    
65           // initialize the applet 
66           a.init(); 
67           a.start(); 
68    
69           // create new application frame window 
70           AppletFrame f = new AppletFrame(title); 
71    
72           // add applet to frame window 
73           f.add("Center", a); 
74    
75           // resize frame window to fit applet 
76           // assumes that the applet sets its own size 
77           // otherwise, you should set a specific size here. 
78           appletSize = a.getSize(); 
79           f.pack(); 
80           f.setSize(appletSize); 
81           f.setSize(200, 200); 
82    
83           // show the window 
84           f.show(); 
85    
86       }  // end startApplet() 
87    
88    
89       // constructor needed to pass window title to class Frame 
90       public AppletFrame(String name) { 
91           // call java.awt.Frame(String) constructor 
92           super(name); 
93       } 
94    
95   }   // end class AppletFrame 
96    
97