/**
* 2018.8.8
* 作者:小孟鱼
* 功能:gui界面开发演示
*/
package com.gui;
import javax.swing.JButton;
import javax.swing.JFrame;
//JFrame是一个顶层容器类(可以添加其他swing组件类)
//JButton也是一个容器类,同样可以加入别的组件
public class Test_gui_1 extends JFrame {
//把需要的swing组件,定义到这里
JButton jb1=null;
public static void main(String[] args) {
//类的对象实例化
Test_gui_1 test_gui_1=new Test_gui_1();
}
//构造函数
public Test_gui_1()
{
//创建一个JButton按钮
jb1=new JButton("我是一个按钮");
//添加JButton组件
this.add(jb1);
//给窗口设置一个标题
this.setTitle("hello,world");
//给窗口设置大小,按像素计算(密度单位)
this.setSize(600, 600);
//显示
this.setVisible(true);
//设置窗口初始位置
this.setLocationRelativeTo(null);
//jf.setLocation(300, 300);
//设置当关闭窗口是,保证JVM也退出
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}