⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.java

📁 该系统能够根据银行用户的要求
💻 JAVA
字号:
/* * 此类实现注册用户界面 */package guiPackage;import static userPackage.ManageUser.InFile;import static userPackage.ManageUser.addUser;import java.awt.BorderLayout;import java.awt.Container;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;		/*类LogIn用于模拟银行的申请帐户*/	public class LogIn implements ActionListener{		private JFrame frame;		private Container contentPane;		private JLabel userLbl, pwdLbl;		private JLabel messLbl;		private JPasswordField pwdTxt;		private JTextField userTxt;		private JButton okBtn, clearBtn, exitBtn;		public LogIn(){			frame = new JFrame("Apply for Account");			frame.setBounds(300, 200, 300, 200);			frame.setResizable(false);			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);			contentPane = frame.getContentPane();			initGUI();		}		public void initGUI(){			userLbl = new JLabel("username: ");			pwdLbl = new JLabel("password: ");			messLbl = new JLabel("welcome");			userTxt = new JTextField(10);			pwdTxt = new JPasswordField(10);			JPanel panel0 = new JPanel(new FlowLayout(FlowLayout.LEFT));			panel0.add(messLbl);			JPanel panel11 = new JPanel(new FlowLayout());			JPanel panel1 = new JPanel(new GridLayout(2, 1));			JPanel panel12 = new JPanel(new FlowLayout());			panel11.add(userLbl);			panel11.add(userTxt);			panel12.add(pwdLbl);			panel12.add(pwdTxt);			panel1.add(panel11);			panel1.add(panel12);						okBtn = new JButton("ok");			clearBtn = new JButton("clear");			exitBtn = new JButton("exit");			JPanel panel2 = new JPanel(new FlowLayout());			panel2.add(okBtn);			panel2.add(clearBtn);			panel2.add(exitBtn);						JPanel pane = new JPanel(new BorderLayout());			pane.add(panel0, BorderLayout.NORTH);			pane.add(panel1, BorderLayout.CENTER);			pane.add(panel2, BorderLayout.SOUTH);			contentPane.add(pane);						okBtn.addActionListener(this);			clearBtn.addActionListener(this);			exitBtn.addActionListener(this);		}		public void actionPerformed(ActionEvent e){			if(e.getSource() == okBtn){				//getText() 返回此 TextComponent(文本框)中包含的文本				//toLowerCase()使用默认语言环境的规则将此 String 中的所有字符都转换为小写。				//trim()返回字符串的副本,忽略前导空白和尾部空白				String name = userTxt.getText().toLowerCase().trim();				String password = pwdTxt.getText().toLowerCase().trim();				if(name.length() == 0){					messLbl.setText("user name cannot be empty!");					userTxt.setText("");					pwdTxt.setText("");					userTxt.grabFocus();//用户名写框里得到交互点				}				else if(password.length() != 6){					messLbl.setText("password must six position!");					userTxt.setText("");					pwdTxt.setText("");					userTxt.grabFocus();				}else{					if(addUser(name, password)){						messLbl.setText("Log In success!");						userTxt.setText("");	                pwdTxt.setText("");	                userTxt.grabFocus();						}					else{						messLbl.setText("repeat Log In!");						userTxt.setText("");						pwdTxt.setText("");						userTxt.grabFocus();						} 				}				return;			}			if(e.getSource() == clearBtn){				userTxt.setText("");				pwdTxt.setText("");				userTxt.grabFocus();				return;			}			//当天结束时保存信息于文件中			if(e.getSource() == exitBtn){				InFile();				frame.hide();			}		}		public void go(){			frame.setVisible(true);		}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -