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

📄 kjhk.java

📁 软件工程学生习作
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
import java.awt.*;import java.sql.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
import javax.swing.*;
import javax.swing.border.*;
/***************************************************************************************************/   
class 查询 extends Panel  implements ActionListener  //查询面板
{Box boxh1,boxv1,boxv2;   
 TextField text1,text2,text3;
  Button button1,button2;
 
  Cursor c=new  Cursor(Cursor.HAND_CURSOR);//光标

  查询()
  {button1=new Button(" 查询 ");   
   button2=new Button("重新输入");
    button1.setBackground(Color.gray); 
     button1.setCursor(c);
     button2.setCursor(c);
   button2.setBackground(Color.gray);   
  
   text1=new TextField (12);
   text2=new TextField (12);
    text2.setEchoChar('*');
   text3=new TextField (12);
   text3.setEditable(false);
   
   boxv1=Box.createVerticalBox();//列式
   boxv1.add(Box.createVerticalStrut(18));
   boxv1.add(new Label("请输入卡号:"));
   boxv1.add(Box.createVerticalStrut(8));
   boxv1.add(new Label("请输入密码:"));
   boxv1.add(Box.createVerticalStrut(8));
   boxv1.add(new Label("您卡上余额:"));
   boxv1.add(Box.createVerticalStrut(20));
   boxv1.add(button1);
   
    boxv2=Box.createVerticalBox();//列式 
    boxv2.add(Box.createVerticalStrut(18));
    boxv2.add(text1);
    boxv2.add(Box.createVerticalStrut(8));
    boxv2.add(text2);
    boxv2.add(Box.createVerticalStrut(8));
    boxv2.add(text3);
    boxv2.add(Box.createVerticalStrut(20));
    boxv2.add(button2);
    
    boxh1=Box.createHorizontalBox();//行式  
    boxh1.add(boxv1);
    boxh1.add(Box.createHorizontalStrut(10));
    boxh1.add(boxv2); 
    add(boxh1);
    
    button1.addActionListener(this);//监视器
    button2.addActionListener(this);
    }
  
  public void actionPerformed (ActionEvent e )//实现监视
     { 
        if(e.getSource()==button1)
         {
         	try{ 查询结果(); }  //  调用数据库函数
          catch(SQLException ee) {}
         	}
         else if(e.getSource()==button2)
              {  
                  text1.setText(null);   
          	      text2.setText(null);
          	         text3.setText(null);   
          	    }	
         	
     	}
    
    public void 查询结果() throws  SQLException   //数据库函数
     {   
        String kahao1,mima1,money1;  int  查询记录=0; 
         
          try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              }
          catch(ClassNotFoundException e) {} 
          
         Connection con=DriverManager.getConnection("jdbc:odbc:redsun","","");
         
        Statement sq1=con.createStatement();
        
        ResultSet rs=sq1.executeQuery("SELECT * FROM 表1 ");
        
       while(rs.next())
            { kahao1=rs.getString("卡号");
             
              mima1=rs.getString("密码");
          
              
              if(kahao1.equals(text1.getText().trim())&&mima1.equals(text2.getText().trim()))
               {   
                   money1=rs.getString("金额");
              
                  text3.setText(money1); 
                 
                 JOptionPane.showMessageDialog(this,"您的卡上余额"+money1,"  消息对话框",
          	      
          	        JOptionPane.QUESTION_MESSAGE); 
          	        
          	        text1.setText(null);   
          	      text2.setText(null);  
          	       text3.setText(null);   
                  
                  
                   查询记录=1;
                     break;
            	}
            	  }
             con.close();	  
      
        if(查询记录==0)//弹出消息对话框
       
          	{    JOptionPane.showMessageDialog(this,"卡号或者密码输入错误","警告对话框",
          	      
          	        JOptionPane.WARNING_MESSAGE);
          	     
          	     text1.setText(null);   
          	      text2.setText(null);  
          	     
           	}
         }
}/***************************************************************************************************/  
 
  
class 取款 extends Panel  implements ActionListener  //取款面板
{Box boxh1,boxv1,boxv2;   
 TextField text1,text2,text3;
  Button button1,button2;
  
  Cursor c=new  Cursor(Cursor.HAND_CURSOR);//光标

 取款()
  {button1=new Button(" 提交 ");
   button2=new Button("重新输入");
      button1.setBackground(Color.gray); 
   button2.setBackground(Color.gray); 
    button1.setCursor(c);
    button2.setCursor(c);
 
   text1=new TextField (15);
   text2=new TextField (15);
    text2.setEchoChar('*');
   text3=new TextField (15);
   
   boxv1=Box.createVerticalBox();//列式
    boxv1.add(Box.createVerticalStrut(20));
   boxv1.add(new Label("请输入卡号:"));
   boxv1.add(Box.createVerticalStrut(8));
   boxv1.add(new Label("请输入密码:"));
   boxv1.add(Box.createVerticalStrut(8));
   boxv1.add(new Label("请输入金额:"));
   boxv1.add(Box.createVerticalStrut(20));
   boxv1.add(button1);
   
    boxv2=Box.createVerticalBox();//列式 
      boxv2.add(Box.createVerticalStrut(20));
    boxv2.add(text1);
    boxv2.add(Box.createVerticalStrut(8));
    boxv2.add(text2);
    boxv2.add(Box.createVerticalStrut(8));
    boxv2.add(text3);
    boxv2.add(Box.createVerticalStrut(20));
    boxv2.add(button2);
    
    boxh1=Box.createHorizontalBox();//行式  
    boxh1.add(boxv1);
    boxh1.add(Box.createHorizontalStrut(10));
    boxh1.add(boxv2); 
    add(boxh1);
    
    button1.addActionListener(this);//监视器
    button2.addActionListener(this);
    }
  
  public void actionPerformed (ActionEvent e )//实现监视
     { 
            if(e.getSource()==button1)
         {
         	
          int nv= JOptionPane.showConfirmDialog(this,"确定取款吗?","确认对话框",
          	      
          	        JOptionPane.YES_NO_OPTION);//弹出确认对话框
         	
           if(nv==JOptionPane.YES_OPTION)//如果点yes.则执行
           {	try{ 提取金额();}	
         	  catch(SQLException ee) {}
         	  }
        
         else if(nv==JOptionPane.NO_OPTION)	//如果点no.则退出清空
         	  text1.setText(null);       	
         	
         	
          }  // 数据库在函数中 
      
         else if(e.getSource()==button2)
              {  
                  text1.setText(null);   
          	      text2.setText(null);
          	      text3.setText(null);   
          	    }	
         	
     	}
    
    public void 提取金额() throws  SQLException   //数据库函数
     { 
        String kahao,mima,money,money1;int money2;int   查询记录=0;
         
          try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              }
          catch(ClassNotFoundException e) {} 
          
         Connection con=DriverManager.getConnection("jdbc:odbc:redsun","","");
         
        Statement sq1=con.createStatement();
           
        ResultSet rs=sq1.executeQuery("SELECT * FROM 表1 ");
         
       while(rs.next())
            { kahao=rs.getString("卡号");
           
              mima=rs.getString("密码");
          
              
              if(kahao.equals(text1.getText().trim())&&mima.equals(text2.getText().trim()))
               {   
                   money=rs.getString("金额");
                   money1=text3.getText().trim();
                   money2=Integer.parseInt(money)-Integer.parseInt(money1);
                   if(money2>=0)
                    {  
                  
                    String q=String.valueOf(money2);
                
                    String temp="UPDATE 表1 SET 金额="+q+" WHERE 卡号="+kahao;
                     con=DriverManager.getConnection("jdbc:odbc:redsun","","");
                    sq1.executeUpdate(temp);con.close();
                    
                     JOptionPane.showMessageDialog(this,"取款交易成功","消息对话框",
          	      
          	        JOptionPane.WARNING_MESSAGE); 
          	        text1.setText(null);   
          	      text2.setText(null);   
          	      text3.setText(null);
                    }
          
                  if(money2<0)
                  { JOptionPane.showMessageDialog(this,"卡上余额不足,请重新输入金额","消息对话框",
          	      
          	        JOptionPane.WARNING_MESSAGE);
          	        text3.setText(null); 
                  }
                   查询记录=1;  
                     break;
            	}
            	  }
            	  
       
        if(查询记录==0)//弹出消息对话框
       
          	{    JOptionPane.showMessageDialog(this,"卡号或密码输入错误","警告对话框",
          	      
          	        JOptionPane.WARNING_MESSAGE);
          	     
          	     text1.setText(null);   
          	      text2.setText(null); 
          	        text3.setText(null);
           	}
         }
}/***************************************************************************************************/  
  
  
class 存款 extends Panel  implements ActionListener  //存款面板
{Box boxh1,boxv1,boxv2;   
 TextField text1,text2;
  Button button1,button2;

  Cursor c=new  Cursor(Cursor.HAND_CURSOR);//光标

  存款()
  {button1=new Button("  提交  ");
   button2=new Button("重新输入");
     button1.setCursor(c);
    button2.setCursor(c);
 
      button1.setBackground(Color.gray); 
   button2.setBackground(Color.gray); 
 
   text1=new TextField (15);
   text2=new TextField (15);
 
 
   
   boxv1=Box.createVerticalBox();//列式
    boxv1.add(Box.createVerticalStrut(30));
   boxv1.add(new Label("请输入卡号: "));
   boxv1.add(Box.createVerticalStrut(8));
   boxv1.add(new Label("输入存款金额:"));
   boxv1.add(Box.createVerticalStrut(30));
   boxv1.add(button1);
   
    boxv2=Box.createVerticalBox();//列式 
    boxv2.add(Box.createVerticalStrut(30));
    boxv2.add(text1);
    boxv2.add(Box.createVerticalStrut(8));
    boxv2.add(text2);
    boxv2.add(Box.createVerticalStrut(30));
    boxv2.add(button2);
    
    boxh1=Box.createHorizontalBox();//行式  
    boxh1.add(boxv1);
    boxh1.add(Box.createHorizontalStrut(20));
    boxh1.add(boxv2); 
    add(boxh1);
    
    button1.addActionListener(this);//监视器
    button2.addActionListener(this);
    }
  
  public void actionPerformed (ActionEvent e )//实现监视
     { 
        if(e.getSource()==button1)
         {
         	
          int nv= JOptionPane.showConfirmDialog(this,"确定要存款吗?","确认对话框",
          	      
          	        JOptionPane.YES_NO_OPTION);//弹出确认对话框
         	
           if(nv==JOptionPane.YES_OPTION)//如果点yes.则执行
           {	try{ 存款金额();}	
         	  catch(SQLException ee) {}
         	  }
        
         else if(nv==JOptionPane.NO_OPTION)	//如果点no.则退出清空
         	  text1.setText(null);       	
         	
         	
          }  // 数据库在函数中
        
         else if(e.getSource()==button2)
              {  
                  text1.setText(null);   
          	      text2.setText(null);
          	  
          	    }	
         	
     	}
    
    public void 存款金额() throws  SQLException   //数据库函数
     { 
        String kahao,money,money1,money3;int money2;   int   查询记录=0;
         
          try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              }
          catch(ClassNotFoundException e) {} 
          
         Connection con=DriverManager.getConnection("jdbc:odbc:redsun","","");
         
        Statement sq1=con.createStatement();
           
        ResultSet rs=sq1.executeQuery("SELECT * FROM 表1 ");
         
       while(rs.next())
            { kahao=rs.getString("卡号");
           
               if(kahao.equals(text1.getText().trim()))
               {   
                   money=rs.getString("金额");
                   money1=text2.getText().trim();
                   money2=Integer.parseInt(money)+Integer.parseInt(money1);
                   money3=String.valueOf(money2);
                  
                    String temp="UPDATE 表1 SET 金额="+money3+" WHERE 卡号="+kahao;
                    con=DriverManager.getConnection("jdbc:odbc:redsun","",""); 
             
                    sq1.executeUpdate(temp);
                    
                     JOptionPane.showMessageDialog(this,"存款交易成功","消息对话框",
          	      
          	        JOptionPane.WARNING_MESSAGE);
                    
                    查询记录=1;
                     text1.setText(null);   
          	      text2.setText(null); 
          	      

⌨️ 快捷键说明

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