parent
19ab13f7e4
commit
41c2a4dc47
@ -0,0 +1,121 @@
|
||||
package com.tyj.viewtyj;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.TableModel;
|
||||
|
||||
import com.tyj.ui.ProductListFrametyj;
|
||||
import com.tyj.ui.MainApptyj;
|
||||
import com.tyj.dao.OrderDaotyj;
|
||||
import com.tyj.dao.OrderDetailDaotyj;
|
||||
import com.tyj.dao.ProductDaotyj;
|
||||
import com.tyj.dao.mysql.OrderDaoImptyj;
|
||||
import com.tyj.dao.mysql.OrderDetailDaoImptyj;
|
||||
import com.tyj.dao.mysql.productDaolmptyj;
|
||||
import com.tyj.domain.Ordertyj;
|
||||
import com.tyj.domain.OrderDetailtyj;
|
||||
import com.tyj.domain.Producttyj;
|
||||
|
||||
|
||||
public class CartFrametyj extends MyFrame {
|
||||
//表格
|
||||
private JTable table;
|
||||
|
||||
//表格数据
|
||||
private Object[][] data = null;
|
||||
|
||||
|
||||
private ProductDaotyj dao = new productDaolmptyj();
|
||||
|
||||
|
||||
private Map<String, Integer> cart;
|
||||
|
||||
private ProductListFrame productListFrame;
|
||||
|
||||
//购物车窗口
|
||||
public CartFrametyj(Map<String, Integer> cart,ProductListFrame productListFrame) {
|
||||
super("商品购物车", 1000, 700);
|
||||
this.cart = cart;
|
||||
this.productListFrame = productListFrame;
|
||||
|
||||
//顶部的面板
|
||||
JPanel topPanel = new JPanel();
|
||||
FlowLayout fl_topPanel = (FlowLayout) topPanel.getLayout();
|
||||
fl_topPanel.setVgap(10);
|
||||
fl_topPanel.setHgap(20);
|
||||
getContentPane().add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
JButton btnReturn = new JButton("\u8FD4\u56DE\u5546\u5217\u8868");
|
||||
btnReturn.setFont(new Font("Microsoft YaHei", Font.PLAIN, 15));
|
||||
topPanel.add(btnReturn);
|
||||
btnReturn.addActionListener(e->{
|
||||
this.productListFrame.setVisible(true);
|
||||
this.setVisible(false);
|
||||
});
|
||||
|
||||
|
||||
|
||||
JButton btuSubmit = new JButton("\u63D0\u4EA4\u88A2\u5355");
|
||||
topPanel.add(btuSubmit);
|
||||
btuSubmit.setFont(new Font("Microsoft YaHei", Font.PLAIN, 15));
|
||||
//中部表格
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
getContentPane().add(scrollPane, BorderLayout.CENTER);
|
||||
scrollPane.setViewportView(getTable());
|
||||
}
|
||||
|
||||
|
||||
//初始化表格
|
||||
private JTable getTable() {
|
||||
JTable table = new JTable();
|
||||
|
||||
//准备数据
|
||||
data = new Object[cart.size()][5];
|
||||
Set<String> keys = this.cart.keySet();
|
||||
int indx = 0;
|
||||
//遍历购物车
|
||||
for (String productid : keys) {
|
||||
Product p = dao.findById(productid);
|
||||
data[indx][0] = p.getProductid();//商品编号
|
||||
data[indx][1] = p.getCname();//商品名
|
||||
data[indx][2] = new Double(p.getUnitcost());//商品单价
|
||||
data[indx][3] = new Integer(cart.get(productid));//商品数量
|
||||
//计算应付金额
|
||||
double amount = (double) data[indx][2] * (int) data[indx][3];
|
||||
data[indx][4] = new Double(amount);//应付金额
|
||||
indx++;
|
||||
}
|
||||
|
||||
//
|
||||
CartTableModel model = new CartTableModel(data);
|
||||
|
||||
if (table == null) {
|
||||
|
||||
// 设置表格字体
|
||||
table = new JTable(model);
|
||||
//设置表格字体
|
||||
table.setFont(new Font("Microsoft YaHei", Font.PLAIN, 16));
|
||||
//设置表格标题字体
|
||||
table.getTableHeader().setFont(new Font("Microsoft YaHei", Font.BOLD, 17));
|
||||
//设置行高
|
||||
table.setRowHeight(51);
|
||||
table.setRowSelectionAllowed(false);
|
||||
|
||||
} else {
|
||||
table.setModel(model);
|
||||
}
|
||||
return table;
|
||||
}}
|
||||
|
||||
|
Loading…
Reference in new issue