1 3 package jodd.util; 4 5 6 import java.awt.Dimension ; 7 import java.awt.Toolkit ; 8 9 import javax.swing.JApplet ; 10 import javax.swing.JFrame ; 11 import javax.swing.JPanel ; 12 13 16 public class AppletUtil { 17 18 21 private static String title(Object o) { 22 String t = o.getClass().toString(); 23 if (t.indexOf("class") != -1) { 24 t = t.substring(6); 25 } 26 return t; 27 } 28 29 30 33 public static void run(JFrame frame, int width, int height) { 34 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 35 frame.setSize(width, height); 36 frame.setVisible(true); 37 } 38 39 40 43 public static void run(JApplet applet, int width, int height) { 44 JFrame frame = new JFrame (title(applet)); 45 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 46 frame.getContentPane().add(applet); 47 frame.setSize(width, height); 48 applet.init(); 49 applet.start(); 50 frame.setVisible(true); 51 } 52 53 56 public static void run(JPanel panel, int width, int height) { 57 JFrame frame = new JFrame (title(panel)); 58 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 59 frame.getContentPane().add(panel); 60 frame.setSize(width, height); 61 frame.setVisible(true); 62 } 63 64 65 68 public static void center(JFrame frame) { 69 Dimension frameSize = frame.getSize(); 70 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 71 frame.setLocation((screenSize.width - frameSize.width) >> 1, (screenSize.height - frameSize.height) >> 1); 72 } 73 } 74 | Popular Tags |