1 3 package thinlet; 4 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.awt.image.*; 8 9 13 public class FrameLauncher extends Frame implements WindowListener { 14 15 private transient Thinlet content; 16 private transient Image doublebuffer; 17 18 29 public FrameLauncher(String title, Thinlet content, int width, int height) { 30 super(title); 31 this.content = content; 32 add(content, BorderLayout.CENTER); 33 addWindowListener(this); 34 pack(); 35 36 Insets is = getInsets(); 37 width += is.left + is.right; 38 height += is.top + is.bottom; 39 Dimension ss = getToolkit().getScreenSize(); 40 width = Math.min(width, ss.width); 41 height = Math.min(height, ss.height); 42 setBounds((ss.width - width) / 2, (ss.height - height) / 2, width, height); 43 setVisible(true); 44 46 int[] pix = new int[16 * 16]; 47 for (int x = 0; x < 16; x++) { 48 int sx = ((x >= 1) && (x <= 9)) ? 1 : (((x >= 11) && (x <= 14)) ? 2 : 0); 49 for (int y = 0; y < 16; y++) { 50 int sy = ((y >= 1) && (y <= 9)) ? 1 : (((y >= 11) && (y <= 14)) ? 2 : 0); 51 pix[y * 16 + x] = ((sx == 0) || (sy == 0)) ? 0xffffffff : 52 ((sx == 1) ? ((sy == 1) ? (((y == 2) && (x >= 2) && (x <= 8)) ? 0xffffffff : 53 (((y >= 3) && (y <= 8)) ? ((x == 5) ? 0xffffffff : (((x == 4) || (x == 6)) ? 54 0xffe8bcbd : 0xffb01416)) : 0xffb01416)) : 0xff377ca4) : 55 ((sy == 1) ? 0xff3a831d : 0xfff2cc9c)); 56 } 57 } 58 setIconImage(createImage(new MemoryImageSource(16, 16, pix, 0, 16))); 59 } 60 61 65 public void update(Graphics g) { 66 paint(g); 67 } 68 69 73 public void paint(Graphics g) { 74 if (doublebuffer == null) { 75 Dimension d = getSize(); 76 doublebuffer = createImage(d.width, d.height); 77 } 78 Graphics dg = doublebuffer.getGraphics(); 79 dg.setClip(g.getClipBounds()); 80 super.paint(dg); 81 dg.dispose(); 82 g.drawImage(doublebuffer, 0, 0, this); 83 } 84 85 90 public void doLayout() { 91 if (doublebuffer != null) { 92 doublebuffer.flush(); 93 doublebuffer = null; 94 } 95 super.doLayout(); 96 } 97 98 104 public void windowClosing(WindowEvent e) { 105 if (content.destroy()) { 106 System.exit(0); 107 } 108 setVisible(true); 109 } 110 public void windowOpened(WindowEvent e) {} 111 public void windowClosed(WindowEvent e) {} 112 public void windowIconified(WindowEvent e) {} 113 public void windowDeiconified(WindowEvent e) {} 114 public void windowActivated(WindowEvent e) {} 115 public void windowDeactivated(WindowEvent e) {} 116 } | Popular Tags |