简单登录注册系统的设计与实现

设计一个系统用户注册登录的图形界面,具备功能:

1. 能够录入姓名和密码;

2. 三个按钮,注册,登录和取消,点击注册按钮,可以读取用户录入的姓名和密码,注册时保存注册信息,点击登录按钮时读取注册信息并与输入的姓名密码比对,登录成功显示在控制台上;

3单击取消按钮,可以清空用户在注册登录界面中录入的用户信息。

package LoginTestFrame;
import java.awt.event.*;
import java.awt. *;
import javax.swing.*;
public class LoginTestFrame extends JFrame implements ActionListener{
final int NUMBER=3;
JTextField inputName=new JTextField (20);
JPasswordField inputPass=new JPasswordField (20);
JLabel promptLbl1=new JLabel("用户名");
JLabel promptLbl2=new JLabel("密码");
int inputCount=0;
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JButton btn1=new JButton("确定");
JButton btn2=new JButton("取消");
LoginTestFrame(){
super("2021-L-登陆界面");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(330,200);
Container ct=this.getContentPane();
ct.setLayout(new GridLayout(3,1));
jp1.setLayout(new FlowLayout());
jp1.add(promptLbl1);
jp1.add(inputName);
ct.add(jp1,BorderLayout.NORTH);
jp2.setLayout(new FlowLayout());
jp2.add(promptLbl2);
jp2.add(inputPass);
ct.add(jp2,BorderLayout.CENTER);
jp3.setLayout(new FlowLayout());
jp3.add(btn1);
jp3.add(btn2);
ct.add(jp3,BorderLayout.SOUTH);
btn1.addActionListener(this);
btn2.addActionListener(this);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e){
if(e.getSource()==btn1){
if(inputCount<NUMBER){
String name=inputName.getText().trim();
String pass=inputPass.getText().trim();
if(!name.equals("L")||name.equals("")){
inputCount++;
String s1="用户名不存在,第"+inputCount+"次输入错误!";
JOptionPane.showMessageDialog(null,s1);
inputName.setText("");
inputPass.setText("");
}
else if (!pass.equals("123456")||pass.equals("")){
inputCount++;
String s1="密码错误,第"+inputCount+"次输入错误!";
JOptionPane.showMessageDialog(null,s1);
inputPass.setText("");
}
else{
inputCount=0;
inputName.setText("");
inputPass.setText("");
String s1="L同学登录成功";
JOptionPane.showMessageDialog(null,s1);
}
}else{
String s1="用户名和密码超过3次错误,登陆失败";
JOptionPane.showMessageDialog(null,s1);
inputName.setText("");
inputPass.setText("");
}
}
else{
System.exit(0);
}
}
public static void main (String[] args){
LoginTestFrame ltf=new LoginTestFrame();
ltf.setVisible(true);
}
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

是啊是啊!

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

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

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

打赏作者

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

抵扣说明:

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

余额充值