import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelEx ception;
public class InitFrame extends JFrame{
private static final long serialVersionUID = 1L;
// 写这个类的目的是提高代码的复用性
// 发现本项目大部分类都需要这些代码 所以建此类减少其他类的代码
public InitFrame()
{
}
public InitFrame(String name,String imageName,final int DEFAULT_WIDTH,final int DEFAULT_HEIGHT)
{
// 设置窗体标题
setTitle(name);
// 设置屏幕大小位置
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
double screenWidth = screenSize.getWidth();
double screenHeight = screenSize.getHeight();
setBounds((int)screenWidth/2-DEFAULT_WIDTH/2,(int)screenHeight/2-DEFAULT_HEIGHT/2,DEFAULT_WIDTH,DEFAULT_HEIGHT);
//设置图标
Image ima = kit.getImage(Split.class.getResource("/resources/"+imageName));
setIconImage(ima);
//设置 观感
String plaf = "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
try {
UIManager.setLookAndFeel(plaf);
} catch (ClassNotFoundException e2) {
e2.printStackTrace();
} catch (InstantiationException e2) {
e2.printStackTrace();
} catch (IllegalAccessException e2) {
e2.printStackTrace();
} catch (UnsupportedLookAndFeelEx ception e2) {
e2.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(this);
}
}
————————————————
版权声明:本文为CSDN博主「明明如月学长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/w605283073/article/details/46572461