Java图形化界面Box布局

初次练习写的代码:

package 数据库图形化界面3;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


public class SQL extends JFrame{
	Box box,boxone,boxtwo;
	Box text1,text2,text3,text4,text5;
	JButton button1,button2;
	public SQL() {
		setLayout(new FlowLayout());
		init();
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	void init() {
		box = Box.createHorizontalBox();
		boxone = Box.createVerticalBox();
		boxtwo = Box.createHorizontalBox();
		button1 = new JButton("添加");
		button2 = new JButton("退出");	
		text1 = Box.createVerticalBox();
		text2 = Box.createVerticalBox();
		text3 = Box.createHorizontalBox();
		text1.add(new JLabel("姓名:"));
		text1.add(new JLabel("学号:"));
		text1.add(new JLabel("性别:"));
		text1.add(new JLabel("院系:"));
		text2.add(new JTextField(10));
		text2.add(new JTextField(10));
		text2.add(new JTextField(10));
		text2.add(new JTextField(10));
		text3.add(new JTextArea(9,35));
		box.add(text1);
		box.add(Box.createHorizontalStrut(215));
		box.add(text2);
		//box.add(Box.createVerticalStrut(10));
		boxone.add(text3);
		add(box);
		add(boxone);
		add(button1);
		add(button2);
	}
}

运行结果如下:

不知道怎么修改这两个按钮的大小,有大佬知道的话,私聊指导一下我,谢谢。


猜你喜欢

转载自blog.csdn.net/qq_40307529/article/details/80699227