java swing开发中,JFrame作为启动窗口,使用时不建议直接new一个JFrame,推荐把JFrame放到一个事件指派线程中启动,也就是通过SwingUtilities.invokeLater方式
package com.zhufeng.demo;
import javax.swing.*;
import java.awt.*;
/**
* @ClassName: ShowJFrame
* @Description TODO
* @author 月夜烛峰
* @date 2022/7/11 17:09
*/
public class ShowJFrame {
JPanel colorPanel = new JPanel();
public void createAndShowGUI(String title) {
//窗口名称
JFrame frame = new JFrame("月夜烛峰-" + title);
//窗口带有关闭按钮
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//指定窗口大小
frame.setSize(new Dimension(400, 300));
//窗口居中展示
frame.setLocationRelativeTo(null);
//窗口设置为可见
frame.setVisible(true);
colorPanel.setName(title);
colorPanel.setBackground(Color.BLACK);
frame.add(colorPanel);
}
public static void main(String[] args) {
javax.swing.Sw