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

📄 atm.java

📁 实现简单的ATM功能
💻 JAVA
字号:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ATM extends JApplet implements ActionListener {
 JLabel passwordLabel;
 JTextField passwordField; 
 String  cString;
 long m=0;
 long value=10000; 
 long q=202074; 
 int n;

 public void init()
   {
     

      Container container = getContentPane();
      container.setLayout( new FlowLayout() );

      

      passwordLabel = new JLabel( "****亲爱的用户您好!欢迎使用本ATM ****请输入您的密码:" );
      container.add( passwordLabel );

     
      passwordField = new JPasswordField( 20);
      container.add( passwordField );
      
      
      passwordField.addActionListener( this );
     
} 
 public void actionPerformed( ActionEvent event )
   {  
   	  long word;
      word = Long.parseLong( passwordField.getText() ); 
      if(word==q)
      {
      	passwordField.setText("");
        try{yu();
        	}catch(Exception ex){};}
      else
          {
          	JOptionPane.showMessageDialog( null, "密码错误!请重新输入!" ,  "Results",
       JOptionPane.PLAIN_MESSAGE ); 
       passwordField.setText("");
      }
}
 public  void yu()throws IOException
   {  
     
     int  n=0;
      String  selString;
      selString = JOptionPane.showInputDialog("请选择以下服务"+"\n请输入服务号: "+"\n\n1.取款"+"\n2.存款"+"\n3.查询余额"+"\n4.修改密码"+"\n5.退出系统") ;
      n = Integer.parseInt(selString);
     
     if(n==1)
        {
          a2();
          try{yu();}catch(Exception ex){};
         }  
      else if(n==2)
        {
         value=a3();
         try{yu();}catch(Exception ex){};
        }  
      else if(n==3)
         {a4();
         try{yu();}catch(Exception ex){};}
      else if(n==4)
        {
           q=a5();
           try{yu();}catch(Exception ex){};
        } 
       if(n==5)
        {
           JOptionPane.showMessageDialog( null, "谢谢您的使用!" ,  "Results",
       JOptionPane.PLAIN_MESSAGE ); 
           
       
       }
       } 
  public  long yu1() throws IOException
     {
      m = Long.parseLong(cString);
      return m; 
     } 
   
    public long a2()
     {  
       
       cString = JOptionPane.showInputDialog("请输入您要取得金额:") ;
      try{
           yu1();
          }catch(Exception ex){};
        
        if(m<value)
           {
             JOptionPane.showMessageDialog( null, "取款成功,你的余额为"+(value-m) ,  "Results",
       JOptionPane.PLAIN_MESSAGE );
             value=value-m;
           } 
        else
           {
             JOptionPane.showMessageDialog( null, "你的余额不足,无法取款" ,  "Results",
       JOptionPane.PLAIN_MESSAGE );    
             
            }
         return value;
  }

    public long a3()
     { 
       cString = JOptionPane.showInputDialog("请输入您要存得金额:") ;
      try{
           yu1();
          }catch(Exception ex){};
       
      if(m<0)
        { 
           JOptionPane.showMessageDialog( null, "操作错误,请重新登陆!" ,  "Results",
       JOptionPane.PLAIN_MESSAGE ); 
           
         }
       else
        { 
           value=value+m;
           JOptionPane.showMessageDialog( null, "存款成功,您的余额为"+value ,  "Results",
       JOptionPane.PLAIN_MESSAGE ); 
         }   
        return value;
      }
   public  void a4()
     {
        
        JOptionPane.showMessageDialog( null, "您的帐户为00000001,您的余额为"+value ,  "Results",
       JOptionPane.PLAIN_MESSAGE );     
      }
  
    public  long  a5()
     {
      long x=0;
         cString = JOptionPane.showInputDialog("请输入您的密码:") ;
         try{
                     yu1();
          }catch(Exception ex){};
       if(m!=q)
             {
               JOptionPane.showMessageDialog( null, "您的密码有误,请重新输入" ,  "Results",
       JOptionPane.PLAIN_MESSAGE );
              return q;
                }
       else
       {         
          cString = JOptionPane.showInputDialog("请输入你的新密码:") ;
            try{
                     yu1();
          }catch(Exception ex){};
        
           
       cString = JOptionPane.showInputDialog("请再次输入你的密码:") ;
         x = Long.parseLong(cString);
            
            if(m!=x)
               { JOptionPane.showMessageDialog( null, "你的密码两次输入不一致,请重新进行修改" ,  "Results",
       JOptionPane.PLAIN_MESSAGE );
             return q;
                }
             else  
           {           
             JOptionPane.showMessageDialog( null, "您的密码修改成功!" ,  "Results",
       JOptionPane.PLAIN_MESSAGE );
             return  m;
            }
       }
           
              }
    }
    













⌨️ 快捷键说明

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