import java.io.IOException;
import java.awt.Font;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.imageio.ImageIO;
public class Frame implements WindowListener {
public static JFrame frame;
public Frame() {
initialize();
}
private void initialize(){
// 新建窗体
frame = new JFrame();
// 设置窗体自动调节大小
frame.pack();
// 设置窗体位置、大小
frame.setBounds(100, 100, 100, 100);
// 设置窗体是否可调节大小
frame.setResizable(false);
// 设置窗体布局
frame.getContentPane().setLayout(null);
// 设置窗体标题
frame.setTitle("Frame");
// 设置窗体字体
frame.setFont(new Font("黑体", Font.PLAIN, 17));
// 设置窗体在屏幕中央打开
frame.setLocationRelativeTo(null);
// 设置窗体默认关闭方式为退出程序
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 设置窗体图标
frame.setIconImage(ImageIO.read(this.getClass().getResource("/priv/image/image.png")));
// 设置窗体观感(皮肤/主题)
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
// 设置窗体是否可见
frame.setVisible(true);
// 添加 WindowListener
frame.addWindowListener(this);
}
/**
* @description 重写 WindowListener
* @param e
*/
public void windowClosing(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
public static void main(String args[]) {
new Frame();
}
}
【Java】JFrame基本参数设置
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 版本记录 前言 很多做视频和图像的,相信对这个框架都不是很陌生,它渲染高级3D图形,并使用GPU执行数据并行计算。...