📄 appletutil.java
字号:
package jodd.util;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* Misc applet utils.
*/
public class AppletUtil {
// create a title string from the class name:
public static String title(Object o) {
String t = o.getClass().toString();
if (t.indexOf("class") != -1) // remove the word "class":
t = t.substring(6);
return t;
}
/**
* Runs a frame.
*
* @param frame
* @param width
* @param height
*/
public static void run(JFrame frame, int width, int height) {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, height);
frame.setVisible(true);
}
/**
* Runs an applet.
*
* @param applet
* @param width
* @param height
*/
public static void run(JApplet applet, int width, int height) {
JFrame frame = new JFrame(title(applet));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width, height);
applet.init();
applet.start();
frame.setVisible(true);
}
/**
* Runs a pannel.
*
* @param panel
* @param width
* @param height
*/
public static void run(JPanel panel, int width, int height) {
JFrame frame = new JFrame(title(panel));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel);
frame.setSize(width, height);
frame.setVisible(true);
}
/**
* Center frame window.
*
* @param frame
*/
public static void center(JFrame frame) {
Dimension frameSize = frame.getSize();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -