JFrame

package com.pinnet.basic.ui;

import java.awt.Color;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.WindowConstants;

public class UI
{

    /**
     * @param title
     * TODO 创建窗口并指定窗口标题
     */
    public static void createJFrame(String title)
    {
        // 窗口标题
        JFrame frame = new JFrame(title); 
        // 窗口可见
        frame.setVisible(true); 
        // 设置窗体大小
        frame.setSize(800, 680); 
        // 位置原点取屏幕左上角 
        // 窗口位置,大小 X,Y,With,Height
        frame.setBounds(100, 100, 800, 680); 
        // 关闭方式
        // WindowConstants.DO_NOTHING_ON_CLOSE = 0;
        // WindowConstants.HIDE_ON_CLOSE = 1;
        // WindowConstants.DISPOSE_ON_CLOSE = 2;
        // WindowConstants.EXIT_ON_CLOSE = 3;
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        // 获取窗口的容器
        // 可用次对象往 JFrame 窗口中添加其他容器
        Container container = frame.getContentPane(); 
        //设置颜色
        container.setBackground(Color.RED);  
    }
}

程序运行结果如下:

你可能感兴趣的:(ui,小玩意,JAVA-Swing)