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

📄 load.java

📁 超市购物系统用于给用户提供购物的选择空间
💻 JAVA
字号:
package windows;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import odbc.Conn;



public class Load implements ActionListener {
	private JFrame log;
	private JLabel midl;
	private JTextField midtf;
	private JButton ok,dbuy,querym,queryg;
	private JPanel p1,p2,p3;
	private static float money=0;
	
    public Load() {                                //构造方法,初始化窗口
    	
        //log
        log=new JFrame("登录");
        log.setSize(new Dimension(350,180));        
        //Label
        midl=new JLabel("会员卡号");
        midl.setFont(new Font("黑体",18,18));    
        //TextField
        midtf=new JTextField(15);
        midtf.setText("");
        midtf.setFont(new Font("黑体",18,18));
        //Button
        ok=new JButton("确定");
        dbuy=new JButton("直接购买");
        querym=new JButton("查询会员信息");
        queryg=new JButton("查询商品信息");
        ok.setFont(new Font("黑体",15,15));
        dbuy.setFont(new Font("黑体",15,15));
        querym.setFont(new Font("黑体",15,15));
        queryg.setFont(new Font("黑体",15,15));
        //Panel
        p1=new JPanel();
        p2=new JPanel();
        p3=new JPanel();
        //log布局
        p1.setLayout(new FlowLayout(FlowLayout.CENTER,12,12));
        p1.add(midl);
        p1.add(midtf);
        p2.setLayout(new FlowLayout(FlowLayout.CENTER,12,12));
        p2.add(ok);
        p2.add(dbuy);
        p3.setLayout(new FlowLayout(FlowLayout.CENTER,12,12));
        p3.add(querym);
        p3.add(queryg);        
        log.setLayout(new BorderLayout());
        log.add("North",p1);
        log.add("Center",p2);
        log.add("South",p3);
        log.setBackground(Color.darkGray);
        log.setLocation(350,300);
        log.setVisible(true);
        log.setResizable(false);
        log.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        //按钮事件监听
        ok.addActionListener(this);
        dbuy.addActionListener(this);
        querym.addActionListener(this);
        queryg.addActionListener(this);
        
    }            //Load()
    
public void actionPerformed(ActionEvent e) {      
		String mid=midtf.getText();
		Pos pos;
		Inf_m inf_m;
		Inf_g inf_g;
		
		if(e.getSource()==ok)                               //会员购买
		 {if( mid.equalsIgnoreCase("") || Integer.parseInt(mid)<=0 || Integer.parseInt(mid)>Conn.mSum())
		   {JOptionPane.showMessageDialog(null,"请输入正确的会员卡号","出错",JOptionPane.ERROR_MESSAGE);
		  }else   
		     {midtf.setText("");
			  try{String sql3="select Mname from members where Mid="+Integer.parseInt(mid);
	              Statement stmt = Conn.getConnection().createStatement();
	              ResultSet rs=stmt.executeQuery(sql3);
	              rs.next();
	              String ss=rs.getString("Mname");
	              JOptionPane.showMessageDialog(null,"欢迎光临","尊敬的会员",JOptionPane.DEFAULT_OPTION);
			      pos=new Pos(ss,mid);
			      stmt.executeUpdate(sql3);
		          rs.close();
		          stmt.close();
		       }catch(Exception e1){
		                e1.getStackTrace();
		        } //catch
		     } //else		    	
		}                                                     
		
	    if(e.getSource()==dbuy)                          //非会员购买
 	    {JOptionPane.showMessageDialog(null,"欢迎光临","尊敬的顾客",JOptionPane.DEFAULT_OPTION);
    	 pos=new Pos("顾客","0");
 	    }                                                    
	    
	    if(e.getSource()==querym)                      //查询会员信息
	    {midtf.setText("");
	     try{if( mid.equalsIgnoreCase("") || Integer.parseInt(mid)<=0 || Integer.parseInt(mid)>Conn.mSum())
		        JOptionPane.showMessageDialog(null,"请输入正确的会员卡号","出错",JOptionPane.ERROR_MESSAGE);		      
	         else  inf_m=new Inf_m(mid);
	      }catch (Exception e1) {
			e1.printStackTrace();
	       }                                            
	    }                                                  
	    
		if(e.getSource()==queryg)                  //查询货品库存量和该收银台的销售量
		{ inf_g=new Inf_g();			
		}                                               
		
	}  //actionPerformed()	
    
    public static void setMoney(float mon) {
    	if(mon>=0)   money=money+mon;
    }
	public static float getMoney() {
		return money;
	}

}

⌨️ 快捷键说明

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