1 3 package thinlet; 4 5 import java.applet.*; 6 import java.awt.*; 7 8 12 public class AppletLauncher extends Applet implements Runnable { 13 14 private transient Thinlet content; 15 private transient Image doublebuffer; 16 17 20 public AppletLauncher() { 21 super(); } 23 24 28 public void init() { 29 setBackground(Color.white); setForeground(Color.darkGray); 30 setLayout(new BorderLayout()); 31 add(new Label("Loading...", Label.CENTER), BorderLayout.CENTER); 32 new Thread (this).start(); 33 } 34 35 42 public void run() { 43 try { 44 Class thinletclass = Class.forName(getParameter("class")); 45 try { 46 content = (Thinlet) thinletclass.getConstructor(new Class [] { 47 Applet.class }).newInstance(new Object [] { this }); 48 } catch (NoSuchMethodException nsme) { 49 content = (Thinlet) thinletclass.newInstance(); 50 } 51 removeAll(); 52 add(content, BorderLayout.CENTER); 53 } catch (Throwable exc) { 54 removeAll(); 55 add(new Label(exc.getClass().getName() + " " + 56 exc.getMessage(), Label.CENTER), BorderLayout.CENTER); 57 } 58 doLayout(); repaint(); 59 } 60 61 65 public void doLayout() { 66 super.doLayout(); 67 if (doublebuffer != null) { 68 doublebuffer.flush(); 69 doublebuffer = null; 70 } 71 } 72 73 77 public void stop() { 78 if (doublebuffer != null) { 79 doublebuffer.flush(); 80 doublebuffer = null; 81 } 82 } 83 84 88 public void update(Graphics g) { 89 paint(g); 90 } 91 92 96 public void paint(Graphics g) { 97 if (doublebuffer == null) { 98 Dimension d = getSize(); 99 doublebuffer = createImage(d.width, d.height); 100 } 101 Graphics dg = doublebuffer.getGraphics(); 102 dg.setClip(g.getClipBounds()); 103 super.paint(dg); 104 dg.dispose(); 105 g.drawImage(doublebuffer, 0, 0, this); 106 } 107 108 113 public void destroy() { 114 content.destroy(); 115 } 116 }
| Popular Tags
|