java Swing第1集:制作JFrame

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Swing第1集:制作JFrame相关的知识,希望对你有一定的参考价值。

import javax.swing.*;

public class Main {

    public static void main(String[] args) {

        //Creates a new window with the title as the parameter
        JFrame window = new JFrame("Title");

        //Makes the window visible because by default, it isn't
        window.setVisible(true);

        //Terminates the whole application when the window is closed.
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //      Nothing happens. You must exit another way
//        window.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
//              Only hides the window, but still uses resources for it
//        window.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
//              Closes the window and un-allocates space for window. This is default. Program will still run.
//        window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        //Sets the location of the window
        window.setLocation(500, 500);
        //Sets Size of window
        window.setSize(1000, 1000);
        //Set both at the same time
        //window.setBounds(500,500,1000,1000);
        
        //episode 1 done lil boi
    }
}

以上是关于java Swing第1集:制作JFrame的主要内容,如果未能解决你的问题,请参考以下文章

《Java Swing》第2节:窗体的创建

如何在 JFrame/JPanel 中可视化控制台 java

Java学习笔记7.1.1 初探Swing世界 - Swing顶级容器

Java学习笔记7.1.1 初探Swing世界 - Swing顶级容器

创建第一个界面程序

14.2-全栈Java笔记: Java Swing创建窗口,原来这么简单!!!