JAVA用户注册界面

import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import javax.swing.*;
import javax.swing.border.EmptyBorder;

public class RegistDemo extends JFrame {
	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField1;
	private JPasswordField passwordField2;

	public static void main(String[] args) {
		RegistDemo frame = new RegistDemo();
		frame.setVisible(true);
	}

	public RegistDemo() {
		setTitle("用户注册");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 350, 250);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new GridLayout(5, 1, 5, 5));

		JPanel panel1 = new JPanel();
		contentPane.add(panel1);

		JLabel label1 = new JLabel("新用户注册");
		panel1.add(label1);

		JPanel panel2 = new JPanel();
		panel2.setLayout(new FlowLayout(FlowLayout.LEFT));
		contentPane.add(panel2);

		JLabel label2 = new JLabel("用  户  名");
		panel2.add(label2);

		textField = new JTextField();
		panel2.add(textField);
		textField.setColumns(18);

		JPanel panel3 = new JPanel();
		panel3.setLayout(new FlowLayout(FlowLayout.LEFT));
		contentPane.add(panel3);

		JLabel label3 = new JLabel("密        码");
		panel3.add(label3);

		passwordField1 = new JPasswordField();
		passwordField1.setColumns(18);
		panel3.add(passwordField1);

		JPanel panel4 = new JPanel();
		panel4.setLayout(new FlowLayout(FlowLayout.LEFT));
		contentPane.add(panel4);

		JLabel label4 = new JLabel("确认密码");
		panel4.add(label4);

		passwordField2 = new JPasswordField();
		passwordField2.setColumns(18);
		panel4.add(passwordField2);

		JPanel panel5 = new JPanel();
		contentPane.add(panel5);

		JButton button = new JButton("提交");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				do_button_actionPerformed(e);
			}
		});
		panel5.add(button);
	}

	protected void do_button_actionPerformed(ActionEvent e) {
		char[] password1 = passwordField1.getPassword();// 获得密码框1中的密码
		char[] password2 = passwordField2.getPassword();// 获得密码框2中的密码
		boolean equals = Arrays.equals(password1, password2);// 判断两个密码框中密码是否相同
		if (equals) {// 如果密码相同则提示注册成功
			JOptionPane.showMessageDialog(this, "用户注册成功!", null,
					JOptionPane.INFORMATION_MESSAGE);
		} else {// 如果密码不同则提示密码不同
			JOptionPane.showMessageDialog(this, "两次密码不同!", null,
					JOptionPane.WARNING_MESSAGE);
		}
	}
}

  • 6
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Stmlker

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值