JAVA_eclipse插件绘制GUI界面过程

JAVA_eclipse插件绘制GUI界面过程

  1. 安装eclipse插件

安装WindowBuilder插件
在这里插入图片描述
选择相应的版本install
在这里插入图片描述

等待下载安装完成重新启动eclipse

  1. 插件的使用

新建项目,选择其他
在这里插入图片描述

新建Application Window
在这里插入图片描述

生成代码界面和design界面
在这里插入图片描述

选择design进行gui界面编辑
在这里插入图片描述

  1. 例如创建一个简易的计算器4*4界面布局

    首先需要是使用布局
    在这里插入图片描述

    其次创建一个文本框TextField

在这里插入图片描述

添加一个面板Panel
在这里插入图片描述

同时面板布局采用GridLayout,自动排列,往面板添加按钮

在这里插入图片描述

左下角设置按钮参数

在这里插入图片描述
依次添加全部按钮最后结果

在这里插入图片描述

自动生成的代码块如下(部分)

/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					caculatetest window = new caculatetest();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public caculatetest() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 522, 504);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		textField = new JTextField();
		textField.setColumns(10);
		
		JPanel panel = new JPanel();
		GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, 484, GroupLayout.PREFERRED_SIZE)
						.addComponent(panel, GroupLayout.PREFERRED_SIZE, 485, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(13, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(textField, GroupLayout.PREFERRED_SIZE, 82, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 349, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(20, Short.MAX_VALUE))
		);
		panel.setLayout(new GridLayout(4, 4, 0, 0));
		
		btnNewButton_1 = new JButton("+");
		btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_1);
		
		btnNewButton = new JButton("-");
		btnNewButton.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton);
		
		btnNewButton_2 = new JButton("x");
		btnNewButton_2.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_2);
		
		btnNewButton_3 = new JButton("/");
		btnNewButton_3.setEnabled(true);
		btnNewButton_3.setFont(new Font("Dialog", Font.PLAIN, 17));
		panel.add(btnNewButton_3);
		
		btnNewButton_4 = new JButton("1");
		btnNewButton_4.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_4);
		
		btnNewButton_5 = new JButton("2");
		btnNewButton_5.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_5);
		
		btnNewButton_6 = new JButton("3");
		btnNewButton_6.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_6);
		
		btnNewButton_7 = new JButton("0");
		btnNewButton_7.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_7);
		
		btnNewButton_8 = new JButton("4");
		btnNewButton_8.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_8);
		
		btnNewButton_9 = new JButton("5");
		btnNewButton_9.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_9);
		
		btnNewButton_10 = new JButton("6");
		btnNewButton_10.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_10);
		
		btnNewButton_11 = new JButton("c");
		btnNewButton_11.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_11);
		
		btnNewButton_12 = new JButton("7");
		btnNewButton_12.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_12);
		
		btnNewButton_13 = new JButton("8");
		btnNewButton_13.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_13);
		
		btnNewButton_14 = new JButton("9");
		btnNewButton_14.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_14);
		
		btnNewButton_15 = new JButton("=");
		btnNewButton_15.setFont(new Font("宋体", Font.PLAIN, 17));
		panel.add(btnNewButton_15);
		frame.getContentPane().setLayout(groupLayout);
  • 8
    点赞
  • 55
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值