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

📄 10.22(jradiobutton有点问题版).txt

📁 模拟atm程序 java语言编写 可以进行密码修改
💻 TXT
📖 第 1 页 / 共 2 页
字号:
						if(amount > userInfo[index].balance)
						JOptionPane.showMessageDialog(null, "No enough money in your account");
						else
						{
						userInfo[index].balance = userInfo[index].balance - amount;
						userInfo[index1].balance = userInfo[index1].balance + amount;
						JOptionPane.showMessageDialog(null, "Transfer Success" + Double.toString(amount));
						businessLabel.setVisible(false);
						businessField.setVisible(false);
						}
					}
					if(flagTrans == true)
					{
						for(int i = 0; i < userInfo.length; i++)
						{
					
							if(businessField.getText().equals(userInfo[i].userNum) && businessField.getText().equals(userInfo[index].userNum))
							{
							JOptionPane.showMessageDialog(null, "Can't transfer to self");
							businessField.setText("");
							break;
							}
						
							if(businessField.getText().equals(userInfo[i].userNum) && !businessField.getText().equals(userInfo[index].userNum))
							{
							businessLabel.setText("How much to transfer and press enter");
							businessField.setText("");
							index1 = i;
							flagTrans = false;
							break;
							}
						
							if(i == userInfo.length - 1)
							{
							JOptionPane.showMessageDialog(null, "No such User");
							businessField.setText("");
							}
																
						}
					}
			 	}
			}
			
			
			
		}
	}
	
	
	public void actionPerformed(ActionEvent event)
	{
		if(event.getActionCommand() == "Account")
		{
			flagAccount = true;
			flagPassword = false;
		}
		
		if(event.getActionCommand() == "Password")
		{
			flagAccount = false;
			flagPassword = true;
		}
		
		if(event.getActionCommand()=="Exit")
			System.exit(0);	
			
	
		if(event.getActionCommand()=="Cancel")
		{
			if(flagAccount == true)
			receiveInput.setText("");
			if(flagPassword == true)
			passwordField.setText("");
		}
		
		
		
		if(event.getActionCommand()=="1")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		}	
		if(event.getActionCommand()=="2")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		}
		
		
		if(event.getActionCommand()=="3")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		}
			
		
		if(event.getActionCommand()=="4")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		}
			
			
		if(event.getActionCommand()=="5")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		}
			
		
		if(event.getActionCommand()=="6")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		}
			
		
		if(event.getActionCommand()=="7")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		}
			
		
		if(event.getActionCommand()=="8")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		}
			
		
		if(event.getActionCommand()=="9")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		
		}
			
		if(event.getActionCommand()=="0")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
		}
		
		
		if(event.getActionCommand()=="00")
		{
			if(flagAccount == true)
			receiveInput.setText(receiveInput.getText() + event.getActionCommand());
			if(flagPassword == true)
			passwordField.setText(passwordField.getText() + event.getActionCommand());
			
		}
			
		
		
		
		for(int i = 0; i < 2; i++)
		if(event.getActionCommand()=="Sure")
		{
		
			if((receiveInput.getText()).equals(userInfo[i].userNum) && ((passwordField.getText()).equals(userInfo[i].password)))
			{	
				loginStatus = true;
				JOptionPane.showMessageDialog(null, "Login Sucessfully!");
				inquiryText.setText("");//下次查询余额时,不会出现上次查询的结果
				index = i;
				break;
			}
			if(i>=userInfo.length - 1)
			{
					JOptionPane.showMessageDialog(null, "Error Account or Password,Input Again!");
					receiveInput.setText("");
					passwordField.setText("");
			}
					
		}
		
		
		
		if(event.getActionCommand() == "Balance Inquiry")
		{
			if(loginStatus == false)
			JOptionPane.showMessageDialog(null, "Login first!");
			else
			{	
				inquiryText.setVisible(true);		
			//	JOptionPane.showMessageDialog(null, "Welcome!");
				String output = "Your Balance is\n ";
				inquiryText.setFont(new Font("",Font.BOLD,30));
				inquiryText.setText(output + userInfo[index].balance);
			}
		}
		
		if(event.getActionCommand() == "Alter Password")
		{
			if(loginStatus == false)
			{
				JOptionPane.showMessageDialog(null, "Login first!");
				flag1 = false;
			}
			else
			{
				prompt.setText("Welcome!");
				flag1 = true;
				oldField.setText("");
				inquiryText.setText("");//下次查询余额时,不会出现上次查询的结果
			}
		}
		
		if(event.getSource().equals(oldField))
		{
			if(loginStatus == false)
				JOptionPane.showMessageDialog(null, "Login first!");
			else 
			{
				if(flag1 == false)
				prompt.setText("Press 'Alter Password' firstly");
				else if(!((oldField.getText()).equals(userInfo[index].password)))
				{
				JOptionPane.showMessageDialog(null, "Incorrect Code");
				flag2 = false;
				}
				else
				{
					flag2 = true;
					prompt.setText("Password Right!Continue...");
				}
			}
		}
		
		if(event.getSource().equals(new2Field))
		{
			if(loginStatus == true)
			{
			
				if(flag1 == true)
				{
					if(flag2 == true)
					{	
						if(!(new1Field.getText()).equals(new2Field.getText()))
						{
						prompt.setText("Two times Input is not same!");
						}
						else
						{
							userInfo[index].password = new2Field.getText();
							prompt.setText("Alter password successful..");
					
						}
					}
				else
				prompt.setText("Input old password firstly");
				}
		//	
			}
			else
				JOptionPane.showMessageDialog(null, "Login first!");
		}
		
		
		
		if(event.getActionCommand()=="Withdrawal")
		{	if(loginStatus == false)
			JOptionPane.showMessageDialog(null, "Login first!");
			else
			{
				inquiryText.setText("");//下次查询余额时,不会出现上次查询的结果
				JOptionPane.showMessageDialog(null, "Welcome!");
				businessLabel.setText("How much to withdrawal and press enter");
				businessField.setText("");
				businessLabel.setVisible(true);
				businessField.setVisible(true);
				flag3 = true;
				flag4 = false;
				flag5 = false;
			
			}
		}
		
		
		
		if(event.getActionCommand() == "   Deposit  ")		
		{	if(loginStatus == false)
			JOptionPane.showMessageDialog(null, "Login first!");
			else
			{
				inquiryText.setText("");//下次查询余额时,不会出现上次查询的结果
				JOptionPane.showMessageDialog(null, "Welcome!");
				businessLabel.setText("How much to deposit and press enter");
				businessField.setText("");
				businessLabel.setVisible(true);
				businessField.setVisible(true);
				flag4 = true;
				flag3 = false;
				flag5 = false;
			}
		}
		
		
		if(event.getActionCommand()  == "   Transfer ")
		{	if(loginStatus == false)
			JOptionPane.showMessageDialog(null, "Login first!");
			else
			{
				JOptionPane.showMessageDialog(null, "Welcome!");
				businessLabel.setText("Enter Transfer Number and press enter");
				businessField.setText("");
			 	businessLabel.setVisible(true);
		 		businessField.setVisible(true);
				flag5 = true;
				flag3 = false;
				flag4 = false;
				flagTrans = true;
				inquiryText.setText("");//下次查询余额时,不会出现上次查询的结果
			//	flagMoney = false;
			}
		}
		
		if((event.getSource()).equals(businessField))
		{
			double amount;
			amount = Double.parseDouble(businessField.getText());
			if(flag3 == true)
			{
				if(amount > userInfo[index].balance)
					JOptionPane.showMessageDialog(null, "No enough money in your account\n     Input again Or exit");
				else
				{
				userInfo[index].balance = userInfo[index].balance - amount;
				JOptionPane.showMessageDialog(null, "Drawal Success " + Double.toString(amount));
				businessLabel.setVisible(false);
				businessField.setVisible(false);
				}
				
			}
			if(flag4 == true)
			{
				userInfo[index].balance = userInfo[index].balance + amount;
				
				JOptionPane.showMessageDialog(null, "Deposit Success " + Double.toString(amount));
				businessLabel.setVisible(false);
				businessField.setVisible(false);
			}
			if(flag5 == true)
			{
				if(flagTrans == false)
				{
				
					if(amount > userInfo[index].balance)
						JOptionPane.showMessageDialog(null, "No enough money in your account");
					else
					{
						userInfo[index].balance = userInfo[index].balance - amount;
						userInfo[index1].balance = userInfo[index1].balance + amount;
						JOptionPane.showMessageDialog(null, "Transfer Success" + Double.toString(amount));
						businessLabel.setVisible(false);
						businessField.setVisible(false);
					}
				}
				if(flagTrans == true)
				{
					for(int i = 0; i < userInfo.length; i++)
					{
					
						if(businessField.getText().equals(userInfo[i].userNum) && businessField.getText().equals(userInfo[index].userNum))
						{
							JOptionPane.showMessageDialog(null, "Can't transfer to self");
							businessField.setText("");
							break;
						}
						
						if(businessField.getText().equals(userInfo[i].userNum) && !businessField.getText().equals(userInfo[index].userNum))
						{
							businessLabel.setText("How much to transfer and press enter");
							businessField.setText("");
							index1 = i;
							flagTrans = false;
							break;
						}
						
						if(i == userInfo.length - 1)
						{
							JOptionPane.showMessageDialog(null, "No such User");
							businessField.setText("");
						}
						
						
					
						
					}
				}
				
				
			
			}
			
		}
		
	}

			
}


class UserInfo
	{
		String userNum;
		String password;
		double balance;
	
		public void setUserNum(String user)
		{
			userNum = user;
		}
	
		public void setPassword(String password)
		{
			this.password = password;
		}
	
		public void setBalance(double balance)
		{
			this.balance = balance;
		}
	}

public class Atm
{
	public static void main(String arg[])
	{
		new MyAtm("ATM");		
	}
}

⌨️ 快捷键说明

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