Java SE (1)之 JFrame 组件 BorderLayout 布局

时间:2023-03-09 22:18:24
Java SE  (1)之 JFrame 组件  BorderLayout 布局

JAVA 初期,练习SE ,桌面程序,

package com.sunzhiyan;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//引入 AWT 包 和swing
public class Demo_1 extends JFrame{ /**
* @param args
*/
JButton button1,button2,button3;
public static void main(String[] args) {
// TODO Auto-generated method stub
Demo_1 demo = new Demo_1("hellow"); }
public Demo_1(String name){
JButton button1 = new JButton("123");
JButton button2 = new JButton("456");
JButton button3 = new JButton("789");
//将按钮添加到this 窗体里面,并且启动BorderLayout布局方式
this.add(button1,BorderLayout.CENTER );
this.add(button2,BorderLayout.EAST );
this.add(button3,BorderLayout.NORTH ); // this.setLayout(new FlowLayout());
//设置窗体所有属性
this.setTitle(name);
this.setSize(400,400);
this.setLocation(100,100);
//设置退出关闭功能
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//开启这个时候,所有的杨样式都会为空
//this.setLayout(null);
//这里是控制这里的THIS 代表的窗体显示与不显示的
//this.setEnabled(true);
this.setVisible(true);
} }