Java 创建窗口

import javax.swing.*;

public class Test extends JFrame {

	public Test() throws Exception {
		// 设置窗体名字
		this.setTitle("窗口名字");
		// 窗体布局设为空
		this.setLayout(null);
		// 设置窗体显示位置和窗口大小
		this.setBounds(X, Y, W, H);

		// 设置你要显示的文字
		JLabel text = new JLabel("请输入饲料名:");
		// 设置窗口内的显示位置和窗口大小
		text.setBounds(X, Y, W, H);
		// 设置文字字体/显示字体风格{1,2,3,4})/字体字号
		text.setFont(new java.awt.Font("微软雅黑", 1, 15));

		// 设置输入框
		JTextField inputField = new JTextField();
		// 设置输入框的显示位置和窗口大小
		inputField.setBounds(X, Y, W, H);

		// 设置按钮
		JButton  buttonName = new JButton("按钮名字"); // 设置文字大小和字体
		buttonName.setFont(new java.awt.Font("微软雅黑", 1, 15)); // 设置按钮位置
		buttonName.setBounds(X, Y, W, H);

		// 添加字体到窗口
		add(text);
		// 添加输入框到窗口
		add(inputField);
		// 添加按钮到窗口
		add(buttonName);

		// 显示界面
		this.setVisible(true);
		// 锁定窗体false自由窗口true
		this.setResizable(false);
	}
	
	public static void main(String[] args) throws Exception {
		// 调用窗口
		new Test();
	}

}

猜你喜欢

转载自blog.csdn.net/weixin_42149650/article/details/81287258