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

📄 atmmain.java

📁 用JAVA 写的模拟ATM取款机系统。自设一个账号密码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import liuchengzhu.*;

    public class ATMmain extends JFrame{
	//----------------------------------------------------
	private JButton aButton[] ,bButton[];
	 
	private JTextArea text,text2,textA[],textB[],textC;
	private JPanel aPanel,aPanel2 ,aPanel3,aPanel4,aPanel5 ;
    private	JButton aButtonCard;
		 
	private int jj=0,money,num=1 ; 
	private static boolean mode=true/*密码和字符的状态*/,mode1=false,mode2=false,
	                  mode3=false,mode4=true,
	                  modepassw=true,modemoney=true,
	                  state1=true,/*金额显示状态*/state2=true;/*功能显示状态*/
	private boolean lock=true;//锁住插卡按钮的标志
    private String string1="",string2="",string3,string4,stringfir="";
 
    card newcard;
	Container container = getContentPane();
 
  //-----------------------------------------------------------	  
	public ATMmain()
	{ 
	super("ATM");
    container.setLayout(null);
    
    //---------------------------------------------------------------- 
    aPanel2 = new JPanel();
    aPanel2 .setBackground(new java.awt.Color(135, 206, 250) );
    aPanel2 .setBounds(/*60*/140 ,30 ,/*360 */200, 90/*200*/  );//显示屏大小
    //==============================================================
    String string = " 欢迎使用ATM.\n "+//初始界面
                    "   请插卡!\n";
         text = new JTextArea(string ,2,10);
         text.setBackground(new java.awt.Color(135, 206, 250)); 
     //===================================
     textC = new JTextArea();
     textC.setBounds(140,120,200,80);
     textC.setBackground(new java.awt.Color(135, 206, 250));
     container.add(textC);//交互区
     //====================================
 // text2 = new JTextArea(50,50);
    aPanel2 .add( text ); 
    container.add(aPanel2 ); 
    aButton = new JButton[10];
    bButton = new JButton[6];
    aPanel = new JPanel( );
    aPanel3 = new JPanel();
    aPanel4 = new JPanel();
    aPanel.setLayout(null);
    aPanel.setBackground(Color.cyan);
    aPanel3.setLayout(null);
    aPanel4.setLayout(null);
   //--------------------------------------
  for(int j=0;j<3;j++)
  {
  
  for(int i=0 ;i<3;i++)
  {
  
     aButton[i+jj] = new JButton(""+(i+jj));
  
   //aButton[i+jj].setBackground(Color.yellow);
   aButton[i+jj].setBounds(  i *85,40*j+50,85,30 );
   aPanel .add(aButton[i+jj]);
   }
      jj+=3;
      
      }//画键盘
  //===================================================    
      for(int i =0;i <3;i ++)
      {
      	bButton[i ] = new JButton(">>");
      bButton[i ].setBounds(0,50*i+50,50,30);
      aPanel3 .add(bButton[i ]);
      } 
      
      for(int i= 3;i<6;i++)
      {
      	bButton[i] = new JButton("<<");
      	bButton[i].setBounds( 0,50*(i-3)+50,50,30);
      aPanel4.add(bButton[i]);
      }//画显示屏两边按钮
  //======================================================
   aButton[9] = new JButton(""+9);
  // aButton[9].setBackground(Color.yellow);
   aButton[9].setBounds(  0,170,85,30 );
   aPanel.add(aButton[9]);
   
   JButton aButton0 = new JButton(" 00");
  // aButton0.setBackground(Color.yellow);
   aButton0.setBounds(  85,170,85,30 );
   aPanel.add(aButton0);
   
   JButton aButtonI = new JButton("确定");
   //aButtonI.setBackground(Color.yellow);
   aButtonI.setBounds(  170,170,85,30 );
   aPanel.add(aButtonI);
   
    aButtonCard = new JButton("插卡器");
       
  // aButtonCard.setBackground(Color.yellow);
   aButtonCard.setBounds(  280,50,150,100 );
   aPanel.add(aButtonCard); 
   
  
   
   JButton aButtonCardq = new JButton("取卡");
   //aButtonCardq.setBackground(Color.yellow);
   aButtonCardq.setBounds(  280,170,150,30 );
   aPanel.add(aButtonCardq); 
   
   container.add(aPanel);
   //画功能按钮
   //==========================================
   
   
   
   
   
    aButtonCard.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent actionevent)
      {
                cardKeyPressed();
            }

        });	
        
         aButtonCardq.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent actionevent)
      {
                cardqKeyPressed();
            }

        });	
        
        
       
       
        for(int j = 0; j < 10; j++)
         aButton[j].addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionevent)
           {
                 digitKeyPressed(Integer.parseInt(actionevent.getActionCommand()));
           }

            });
            
            
            
            //======================================================    
           
           bButton[0].addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent actionevent)
                {  
                     powerKeyPressed(  0  );
                }

            });
            
              
           bButton[1].addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent actionevent)
                {  
                     powerKeyPressed(  1  );
                }

            });
              
           bButton[2].addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent actionevent)
                {  
                     powerKeyPressed(  2  );
                }

            });
              
           bButton[3].addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent actionevent)
                {  
                     powerKeyPressed(  3  );
                }

            });
              
           bButton[4].addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent actionevent)
                {  
                     powerKeyPressed( 4  );
                }

            });
              
           bButton[5].addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent actionevent)
                {  
                     powerKeyPressed( 5  );//功能键的响应
                }

            });
           ///===================================================== 
            aButton0.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent actionevent)
                {
                     two0KeyPressed(   );//00键的响应
                }

            });
                
               aButtonI.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent actionevent)
                {
                     enterKeyPressed(   );// 确定键的响应
                }

            });
            
      // ===================================
      textA = new JTextArea[6];
      for(int i=0;i<6;i++)
    
    textA[i] = new JTextArea();
      
     for(int i=0;i<6;i++)
    textA[i] .setBackground(Color.cyan); //
    
     for(int i=0;i<3;i++)
    textA[i].setBounds(60 ,70+50*i,60 , 30); 
     for(int i=3;i<6;i++)
    textA[i].setBounds(360 ,70+50*(i-3),60 , 30); 
   
     for( int i=0;i<6;i++)
   container.add(textA[i]);  
   
   for(int i=0;i<6;i++)
    textA[i].setVisible(   !state1);
    
    for(int i=0;i<5;i++)
     
     textA[i].setText((i+1)+"00元");
      
     textA[5].setText("其他金额"); 
  //===========================================
     textB = new JTextArea[4];
      
      for(int i=0;i<4;i++)
     textB[i] = new JTextArea();
      
     for(int i=0;i<4;i++)
    textB[i] .setBackground(Color.cyan); //
    
     for(int i=0;i<3;i++)
    textB[i].setBounds(60 ,70+50*i,60 , 30); 
     textB[3].setBounds(360 ,170,60 , 30); 
    
     for( int i=0;i<4;i++)
   container.add(textB[i]);  
   for(int i=0;i<4;i++)
    textB[i].setVisible( !state2);
 
    textB[0].setText("取款");
    textB[1].setText("查询");
    textB[2].setText("更改密码");
    textB[3].setText("退出系统"); 
     //======================================      
  //**********************************************************          
   text2 = new JTextArea( 1 ,15   );
 // text2.setBackground(Color.yellow);
               
   aPanel2 .add( text2 );
   
   container.add(aPanel2  );
   text2.setVisible(false);   
/**/ 
   container.add(aPanel3);
   container.add(aPanel4);
   aPanel.setBounds(20 ,300,450 , 220);//键盘区大小
   aPanel3.setBounds(0,20,50,200 );    //显示屏左边区域大小
   aPanel4.setBounds(430,20,50,200 );  //显示屏右边区域大小
   setBounds(220,125,500,600 );        //面板大小 
   setVisible(true); 
		 
	//**********************************************************
    }    private synchronized void cardKeyPressed()
         {  if(lock)
            {
            	newcard = new card();
            mode3=true;
           // string2="";
             text2.setText("请输入密码");
             textC.setText("");
            text2.setVisible(true); 
         } 
         lock=false;
         }

⌨️ 快捷键说明

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