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

📄 loginframe.java

📁 简易银行卡管理系统作为ATM的模拟系统
💻 JAVA
字号:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginFrame extends JFrame implements ActionListener{
	private static final long serialVersionUID = 1L;
	private JTextField usernameTF;
	private JPasswordField passwordTF;
	private JButton loginButton;
	private JButton cancelButton;
	private JButton newAccount;
	LoginFrame(){
		usernameTF=new JTextField(15);
		passwordTF=new JPasswordField(15);
		
		JPanel userInfo=new JPanel();
		JPanel userInfo1=new JPanel();
		userInfo1.add(new javax.swing.JLabel("username:"));
		userInfo1.add(usernameTF);
		JPanel userInfo2=new JPanel();
		userInfo2.add(new javax.swing.JLabel("password:"));
		userInfo2.add(passwordTF);
		userInfo.add(userInfo1);
		userInfo.add(userInfo2);
		
		JPanel buttons=new JPanel();
		loginButton=new JButton("Login");
		cancelButton=new JButton("Cancel");
		newAccount=new JButton("NewAccount");
		buttons.add(loginButton);
		buttons.add(cancelButton);
		buttons.add(newAccount);
		
		loginButton.addActionListener(this);
		cancelButton.addActionListener(this);
		newAccount.addActionListener(this);
		this.setLayout(new BorderLayout());
		this.add(userInfo,BorderLayout.CENTER);
		this.add(buttons,BorderLayout.SOUTH);
		this.setSize(280,200);
	}
	
	@Override
	public void actionPerformed(ActionEvent event) {
		String command=event.getActionCommand();
		if(command.equals(loginButton.getText())){
			String username=usernameTF.getText();
			char password[]=passwordTF.getPassword();
			if(!login(username,password))
				passwordTF.setText("");
		}
		else if(command.equals(cancelButton.getText())){
			System.exit(0);
		}
		else if(command.equals(newAccount.getText())){
			this.setVisible(false);
			new NewAccount(this).setVisible(true);
		}
	}
	private boolean login(String username, char[] password) {
		User user=Const.getUser(usernameTF.getText(),passwordTF.getPassword());
		if(user==null)return false;
		if(user.getFlag()!=0){
			JOptionPane.showMessageDialog(this, "该帐号已挂失!");
			return false;
		}
		WorkFrame work=new WorkFrame(this,user);
		work.setVisible(true);
		this.setVisible(false);
		return true;
	}

	public static void main(String[]args){
		JFrame account=new LoginFrame();
		account.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		account.setVisible(true);
	}
}

⌨️ 快捷键说明

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