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

📄 shopframe.java

📁 关于shopmanager的源码
💻 JAVA
字号:
package showframe;

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

import businesslogic.ShopLogic;
import dao.ShoppingListDAO;;
public class Shopframe extends JFrame implements ActionListener {
      JLabel l1,l2,l3,l4,l5,l6,l7;
      JTextField t1,t2,t3,t4,t5,t6;
      JButton b1,b2,b3;
	  JPanel p1,p2,p3,p4;
	  JScrollPane sp;
	  JTable ta;
	  String userid;
	  String id;
	  String m;
	  int number;
	 
	  private ShopLogic shoplogic=new ShopLogic();
	  String[]  colNames={"用户ID","商品ID","商品名称","数目","单价",}; 
	  String[][] shopList=new String[20][5];
	  private ShoppingListDAO shdao=new ShoppingListDAO();
	public Shopframe(){
		Container c=this.getContentPane();
		c.setLayout(new BorderLayout());
		l1=new JLabel("用户ID:");
		l2=new JLabel("商品ID:");
		l3=new JLabel("商品个数:");
		l4=new JLabel("应收:");
		l5=new JLabel("实付:");
		l6=new JLabel("找零:");
		t1=new JTextField(10);
		t1.setEditable(false);
		t2=new JTextField(10);
		t3=new JTextField(10);
		t4=new JTextField(10);
		t4.setEditable(false);//不可编辑
		t5=new JTextField(10);
		t6=new JTextField(10);
		t6.setEditable(false);
		b1=new JButton("确定");
		b2=new JButton("结帐");
		b3=new JButton("退出");
		ta=new JTable(shopList,colNames);
        p1=new JPanel();
		p2=new JPanel();
		p3=new JPanel();
		p4=new JPanel(new GridLayout(3,1,0,0));
		sp=new JScrollPane(ta,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		p1.setBounds(0,5,500,25);
		p2.setBounds(0,30,500,50);
		sp.setBounds(0,80, 500, 220);
		
		p1.add(l1);
		p1.add(t1);
		p1.add(b3);
		p2.add(l2);
		p2.add(t2);
		p2.add(l3);
		p2.add(t3);
	    p2.add(b1);
	    p2.add(b2);
		p3.add(l4);
		p3.add(t4);
		p3.add(l5);
		p3.add(t5);
		p3.add(l6);
		p3.add(t6);
		p4.add(p1);
		p4.add(p2);
		p4.add(p3);
		c.add(p4,"North");
		//c.add(p2,"Center");
		c.add(sp);
		//c.add(p3,"South");
		
		sp.setBorder(BorderFactory.createTitledBorder("商品清单"));
		this.setTitle("购物车");
		this.setBounds(300, 100, 500, 300);
		this.setVisible(true);
      
		b1.addActionListener(this);
		b2.addActionListener(this);
		b3.addActionListener(this);
	}
	public void actionPerformed(ActionEvent e){
        Object src=e.getSource();
		
		int i=(int)(Math.random()*10000000);
		userid=Integer.toString(i);
		t1.setText(userid);
		id=t2.getText().trim();
		String st=t3.getText().trim();
		number=Integer.parseInt(st);
		
		ResultSet rs;
		int k=0;
		if(src==b1){
			rs=shdao.executeQuery(id);
			try{
			if(rs.next()){
			shoplogic.checkout(userid,id,number);
			shoplogic.purchase(userid, id, number);
			Double.parseDouble(t5.getText());
			String str=Double.toString(shoplogic.checkout(userid,id,number));
			t4.setText(str);
			shopList[k][0] = rs.getString(1);
			shopList[k][1] = rs.getString(2);
			shopList[k][2] = rs.getString(3);
			shopList[k][3] = rs.getString(4);
			shopList[k][4] = rs.getString(5);
			k++;	
			
			
			}
			else{
				JOptionPane.showMessageDialog(this, "对不起,商品不存在!", "警告", JOptionPane.INFORMATION_MESSAGE);
			}
			}catch(SQLException ee){
				System.err.println(ee.getMessage());
			}
			ta.repaint();
		}
		if(src==b2){
			Double t=Double.parseDouble(t5.getText())-shoplogic.checkout(userid,id,number);
			if(t<0){
				JOptionPane.showMessageDialog(this, "对不起,您付的钱不不足!", "警告", JOptionPane.INFORMATION_MESSAGE);
			}else{
			String sn=Double.toString(t);
			t6.setText(sn);
			}
		}
		if(src==b3){
			System.exit(0);
		}
	}
	public static void main(String args[]){
		new Shopframe();
       
	}
}

⌨️ 快捷键说明

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