Compare commits
27 Commits
@ -0,0 +1,19 @@
|
||||
package view;
|
||||
|
||||
public class Alipay extends MyFrame {
|
||||
|
||||
public Alipay(String title, int width, int height) {
|
||||
super(title, width, height);
|
||||
this.tubiao();
|
||||
// TODO 自动生成的构造函数存根
|
||||
}
|
||||
|
||||
public void tubiao() {
|
||||
MyFrame.setTitleImage(this,"4.png" );
|
||||
MyFrame.setBackgroundImage(this,"1.jpg");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,161 @@
|
||||
package com.tyj.ui;
|
||||
|
||||
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.ProductListFrame;
|
||||
import com.tyj.ui.MainApp;
|
||||
import com.tyj.dao.OrderDao;
|
||||
import com.tyj.dao.OrderDetailDao;
|
||||
import com.tyj.dao.ProductDao;
|
||||
import com.tyj.dao.mysql.OrderDaoImp;
|
||||
import com.tyj.dao.mysql.OrderDetailDaoImp;
|
||||
import com.tyj.dao.mysql.productDaolmp;
|
||||
import com.tyj.domain.Order;
|
||||
import com.tyj.domain.OrderDetail;
|
||||
import com.tyj.domain.Product;
|
||||
|
||||
|
||||
public class CartFrametyj extends MyFrametyj {
|
||||
//表格
|
||||
private JTable table;
|
||||
|
||||
//表格数据
|
||||
private Object[][] data = null;
|
||||
|
||||
|
||||
private ProductDao dao = new productDaolmp();
|
||||
|
||||
|
||||
private Map<String, Integer> cart;
|
||||
|
||||
private ProductListFrame productListFrame;
|
||||
|
||||
//prodcutlistframe窗口
|
||||
public CartFrame(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());
|
||||
|
||||
//提交订单
|
||||
btuSubmit.addActionListener(e -> {
|
||||
//
|
||||
generateOrders();
|
||||
|
||||
JLabel label = new JLabel("确认提交");
|
||||
label.setFont(new Font("Microsoft YaHei", Font.PLAIN, 15));
|
||||
if (JOptionPane.showConfirmDialog(this, label, "", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
// TODO
|
||||
PayFrame p=new PayFrame();
|
||||
p.setVisible(true);
|
||||
} else {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
btnReturn.addActionListener(e -> {
|
||||
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
|
||||
String productid = (String) data[i][0];
|
||||
|
||||
Integer quantity = (Integer) data[i][3];
|
||||
cart.put(productid, quantity);
|
||||
}
|
||||
this.productListFrame.setVisible(true);
|
||||
setVisible(false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void generateOrders() {
|
||||
// TODO 自动生成的方法存根
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//初始化表格
|
||||
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.getmenuid();//商品编号
|
||||
data[indx][1] = p.getName();//商品名
|
||||
data[indx][2] = new Double(p.getPrice());//商品单价
|
||||
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;
|
||||
}}
|
||||
|
||||
|
@ -0,0 +1,61 @@
|
||||
package view;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
import domain.Dishwcy;
|
||||
|
||||
public class DishTableModelwcy extends AbstractTableModel {
|
||||
//表格列名columnNames
|
||||
private String[] columnNames = {"商品编号","商品类型","商品中文名"};
|
||||
//表格中的内容保存在List<Dish>集合中
|
||||
private List<Dishwcy> dishs = null;
|
||||
public DishTableModelwcy(List<Dishwcy> dishs) {
|
||||
this.dishs=dishs;
|
||||
}
|
||||
|
||||
//返回行数
|
||||
@Override
|
||||
//重写了 getRowCount 方法,返回表格的行数,即 dishs 列表的大小。
|
||||
public int getRowCount() {
|
||||
// TODO 自动生成的方法存根
|
||||
return dishs.size();
|
||||
}
|
||||
|
||||
//返回列数
|
||||
@Override
|
||||
//重写了 getColumnCount 方法,返回表格的列数,即 columnNames 数组的长度。
|
||||
public int getColumnCount() {
|
||||
// TODO 自动生成的方法存根
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
//重写了 getValueAt 方法,根据给定的行索引和列索引返回单元格的值。使用 switch 语句根据列索引返回相应的 Dishwcy 对象的属性值
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
// TODO 自动生成的方法存根
|
||||
// 每一行就是一个Dish商品对象
|
||||
Dishwcy p = dishs.get(rowIndex);
|
||||
|
||||
switch(columnIndex) {
|
||||
case 0:
|
||||
return p.getDishid();// 第一列商品编号
|
||||
case 1:
|
||||
return p.getCategory();// 第二列商品编号
|
||||
case 2:
|
||||
return p.getCname();// 第三列商品编号
|
||||
//default:
|
||||
//return p.getEname();
|
||||
|
||||
|
||||
}
|
||||
return p;
|
||||
|
||||
}
|
||||
//定义了 getColumnName 方法,根据列索引返回列名。
|
||||
public String getColumnName(int columnIndex) {
|
||||
return columnNames[columnIndex];
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package view;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
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 dao.OrdersDAOtyj;
|
||||
|
||||
import dao.impl.OrdersDaoImpltyj;
|
||||
|
||||
|
||||
import domain.Orderstyj;
|
||||
|
||||
|
||||
public class JiedanFramembz extends MyFrame {
|
||||
//表格
|
||||
private JTable table;
|
||||
//表格数据
|
||||
private Object[][] data=null;
|
||||
//商品DAO
|
||||
private OrdersDAOtyj dao=new OrdersDaoImpltyj();
|
||||
//购物车数据
|
||||
private Map<Long,Integer> cart;
|
||||
//ProductListFrame窗口
|
||||
private OrderListFramembz orderListFrame;
|
||||
public JiedanFramembz(Map<Long,Integer> cart,OrderListFramembz orderListFrame) {
|
||||
super("接单列表", 1000, 700);
|
||||
// TODO 自动生成的构造函数存根
|
||||
this.tubiao();
|
||||
this.cart=cart;
|
||||
this.orderListFrame=orderListFrame;
|
||||
|
||||
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("返回订单列表");
|
||||
btnReturn.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
topPanel.add(btnReturn);
|
||||
|
||||
JButton btnSubmit = new JButton("确认订单");
|
||||
btnReturn.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
topPanel.add(btnSubmit);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
getContentPane().add(scrollPane, BorderLayout.CENTER);
|
||||
scrollPane.setViewportView(getTable());
|
||||
|
||||
btnSubmit.addActionListener(e->{
|
||||
//生成订单
|
||||
JLabel label = new JLabel("订单已生成,是否接单出发");
|
||||
label.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
if(JOptionPane.showConfirmDialog(this, label, "信息", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION) {
|
||||
System.exit(0);
|
||||
}else {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
private JTable getTable() {
|
||||
// TODO 自动生成的方法存根
|
||||
data = new Object[cart.size()][4];
|
||||
Set<Long> keys = this.cart.keySet();
|
||||
int indx=0;
|
||||
for(Long orderid : keys) {
|
||||
Orderstyj o = dao.findById(orderid);
|
||||
data[indx][0]=o.getOrderid();
|
||||
data[indx][1]=o.getUserid();
|
||||
data[indx][2]=o.getOrderdate();
|
||||
indx++;
|
||||
}
|
||||
|
||||
TableModel model=new JiedanTableModelmbz(data);
|
||||
|
||||
if (table == null) {
|
||||
// 创建表
|
||||
table = new JTable(model);
|
||||
// 设置表中内容字体
|
||||
table.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
||||
// 设置表列标题字体
|
||||
table.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 16));
|
||||
// 设置表行高
|
||||
table.setRowHeight(51);
|
||||
table.setRowSelectionAllowed(false);
|
||||
|
||||
} else {
|
||||
table.setModel(model);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
public void tubiao() {
|
||||
MyFrame.setTitleImage(this,"e39b4ce2ebe83d39adabb339c23a1e0.png" );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.zzy.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class LoginFrame extends JFrame {
|
||||
|
||||
private JTextField txtAccountId;
|
||||
private JPasswordField txtPassword;
|
||||
|
||||
public LoginFrame(String title, int width, int height) {
|
||||
super(title);
|
||||
// TODO
|
||||
|
||||
getContentPane().setLayout(null);
|
||||
|
||||
JLabel label1 = new JLabel("账号:");
|
||||
label1.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
label1.setBounds(51, 33, 83, 30);
|
||||
label1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
||||
getContentPane().add(label1);
|
||||
|
||||
txtAccountId = new JTextField(10);
|
||||
txtAccountId.setBounds(158, 33, 157, 30);
|
||||
txtAccountId.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
||||
getContentPane().add(txtAccountId);
|
||||
|
||||
JLabel label2 = new JLabel("密码:");
|
||||
label2.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
label2.setBounds(51, 85, 83, 30);
|
||||
label2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
||||
getContentPane().add(label2);
|
||||
|
||||
txtPassword = new JPasswordField(10);
|
||||
txtPassword.setBounds(158, 85, 157, 30);
|
||||
txtPassword.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
||||
getContentPane().add(txtPassword);
|
||||
|
||||
JButton btnOK = new JButton("确定");
|
||||
btnOK.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
||||
btnOK.setBounds(61, 140, 100, 30);
|
||||
getContentPane().add(btnOK);
|
||||
|
||||
JButton btnCancel = new JButton("取消");
|
||||
btnCancel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
||||
btnCancel.setBounds(225, 140, 100, 30);
|
||||
getContentPane().add(btnCancel);
|
||||
|
||||
btnOK.addActionListener(e -> {
|
||||
// 登录逻辑
|
||||
});
|
||||
|
||||
btnCancel.addActionListener(e -> {
|
||||
// 退出系统
|
||||
System.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getContentPane() {
|
||||
return super.getContentPane();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean b) {
|
||||
super.setVisible(b);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.zzy.ui;
|
||||
|
||||
import com.zzy.domain.Accountzzy;
|
||||
|
||||
public class MainApp {
|
||||
//用户登录成功后,需要登陆用户数据
|
||||
public static Accountzzy account;
|
||||
//Session(会话)
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 调用Login'frame
|
||||
LoginFrame loginFrame = new LoginFrame("用户登录",400,250);
|
||||
loginFrame.setVisible(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.JButton;
|
||||
|
||||
public class PayFrame extends MyFrame{
|
||||
|
||||
public PayFrame() {
|
||||
super("支付方式", 400,230);
|
||||
this.tubiao();
|
||||
|
||||
getContentPane().setLayout(null);
|
||||
|
||||
JButton btnWeChat =new JButton();
|
||||
btnWeChat.setText("微信支付");
|
||||
btnWeChat.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
btnWeChat.setBounds(120, 50, 150, 30);
|
||||
getContentPane().add(btnWeChat);
|
||||
|
||||
|
||||
JButton btnAlipay =new JButton();
|
||||
btnAlipay.setText("支付宝支付");
|
||||
btnAlipay.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
btnAlipay.setBounds(120, 100, 150, 30);
|
||||
getContentPane().add(btnAlipay);
|
||||
|
||||
//btnUser的的ActionEvent事件监听器
|
||||
btnWeChat.addActionListener(e->{
|
||||
WeChatPay w=new WeChatPay("微信支付", 476, 650);
|
||||
w.setVisible(true);
|
||||
setVisible(false);
|
||||
|
||||
|
||||
});
|
||||
//btnRider的的ActionEvent事件监听器
|
||||
btnAlipay.addActionListener(e->{
|
||||
Alipay a=new Alipay("支付宝支付", 574, 650);
|
||||
a.setVisible(true);
|
||||
setVisible(false);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void tubiao() {
|
||||
// TODO 自动生成的方法存根
|
||||
MyFrame.setTitleImage(this,"4.png" );
|
||||
MyFrame.setBackgroundImage(this,"3.jpg");
|
||||
}
|
||||
}
|
@ -0,0 +1,248 @@
|
||||
package com.tyj.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
import com.tyj.dao.ProductDao;
|
||||
import com.tyj.dao.mysql.productDaolmp;
|
||||
import com.tyj.domain.Product;
|
||||
|
||||
public class ProductListFrame extends MyFrametyj{
|
||||
|
||||
private JTable table;
|
||||
private JLabel lblImage;
|
||||
private JLabel lblPrice;
|
||||
private JLabel lblBrief;
|
||||
private JLabel lblPrice1;
|
||||
|
||||
private List<Product> products = null;
|
||||
private ProductDao pdao = new productDaolmp();
|
||||
|
||||
private Map<String,Integer> cart = new HashMap<String,Integer>();
|
||||
private int selectedRow = -1;
|
||||
public ProductListFrame() {
|
||||
super("商品列表", 1000, 700);
|
||||
|
||||
products = pdao.findAll();
|
||||
getContentPane().add(getSearchPanel(),BorderLayout.NORTH);
|
||||
JSplitPane splitPane = new JSplitPane();
|
||||
splitPane.setDividerLocation(600);
|
||||
splitPane.setLeftComponent(getLeftPanel());
|
||||
splitPane.setRightComponent(getRightPanel());
|
||||
getContentPane().add(splitPane,BorderLayout.CENTER);
|
||||
}
|
||||
//初始化右侧面板
|
||||
private JPanel getRightPanel() {
|
||||
JPanel rightPanel = new JPanel();
|
||||
rightPanel.setBackground(Color.WHITE);
|
||||
|
||||
rightPanel.setLayout(new GridLayout(2,1,0,0));
|
||||
|
||||
lblImage = new JLabel();
|
||||
rightPanel.add(lblImage);
|
||||
lblImage.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
JPanel detailPanel = new JPanel();
|
||||
detailPanel.setBackground(Color.WHITE);
|
||||
rightPanel.add(detailPanel);
|
||||
detailPanel.setLayout(new GridLayout(8,1,0,5));
|
||||
|
||||
JSeparator separator_1 = new JSeparator();
|
||||
detailPanel.add(separator_1);
|
||||
|
||||
lblListprice = new JLabel();
|
||||
detailPanel.add(lblListprice);
|
||||
//设置字体
|
||||
lblPrice.setFont(new Font("微软雅黑",Font.PLAIN,16));
|
||||
|
||||
lblPrice1 = new JLabel();
|
||||
detailPanel.add(lblPrice1);
|
||||
//设置字体
|
||||
lblPrice1.setFont(new Font("微软雅黑",Font.PLAIN,16));
|
||||
|
||||
lblBrief = new JLabel();
|
||||
detailPanel.add(lblBrief);
|
||||
//设置字体
|
||||
lblDescn.setFont(new Font("微软雅黑",Font.PLAIN,16));
|
||||
|
||||
JSeparator separator_2 = new JSeparator();
|
||||
detailPanel.add(separator_2);
|
||||
|
||||
JButton btnAdd = new JButton("添加到购物车");
|
||||
btnAdd.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
detailPanel.add(btnAdd);
|
||||
|
||||
//布局占位使用
|
||||
JLabel lb1 =new JLabel("");
|
||||
detailPanel.add(lb1);
|
||||
|
||||
JButton btnCheck = new JButton("查看购物车");
|
||||
btnCheck.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
detailPanel.add(btnCheck);
|
||||
|
||||
//注册【添加到购物车】按钮的ActionEvent事件监听器
|
||||
btnAdd.addActionListener(e ->{
|
||||
|
||||
if(selectedRow < 0) {
|
||||
return;
|
||||
}
|
||||
//添加商品到购物车处理
|
||||
Product selectProduct = products.get(selectedRow);
|
||||
String productid = selectProduct.getProductid();
|
||||
|
||||
if(cart.containsKey(productid)) {//购物车中已经有该商品
|
||||
//获得商品数量
|
||||
Integer quantity = cart.get(productid);
|
||||
cart.put(productid, ++quantity);
|
||||
}else {//购物车中还没有还商品
|
||||
cart.put(productid, 1);
|
||||
}
|
||||
System.out.println(cart);
|
||||
});
|
||||
|
||||
|
||||
btnCheck.setFont(new Font("Microsoft YaHei UI",Font.PLAIN,15));
|
||||
detailPanel.add(btnAdd);
|
||||
|
||||
JButton btnCheck1 = new JButton("\u67E5\u7788\u8D2D\u7269\u8F66");
|
||||
//注册【查看购物车】按钮的ActionEvent事件监听器
|
||||
//查看购物车
|
||||
btnCheck1.addActionListener(e -> {
|
||||
CartFrame cartFrame=new CartFrame(cart,this);
|
||||
cartFrame.setVisible(true);
|
||||
this.setVisible(false);
|
||||
});
|
||||
btnCheck1.setFont(new Font("Microsoft YaHei UI",Font.PLAIN,15));
|
||||
detailPanel.add(btnCheck1);
|
||||
|
||||
return rightPanel;
|
||||
}
|
||||
//初始化左侧面板
|
||||
private JScrollPane getLeftPanel() {
|
||||
JScrollPane leftScrollPane = new JScrollPane();
|
||||
//将表格作为滚动面板的各个视口试图
|
||||
leftScrollPane.setViewportView(getTable());
|
||||
return leftScrollPane;
|
||||
}
|
||||
//初始化左侧面板中的表格控件
|
||||
private JTable getTable() {
|
||||
ProductTableModel model = new ProductTableModel(this.products);
|
||||
|
||||
if(table == null) {
|
||||
table = new JTable(model);
|
||||
//设置表中内容字体
|
||||
table.setFont(new Font("微软雅黑",Font.PLAIN,16));
|
||||
//设置表列标题字体
|
||||
table.getTableHeader().setFont(new Font("微软雅黑",Font.BOLD,16));
|
||||
//设置表行高
|
||||
table.setRowHeight(51);
|
||||
table.setRowSelectionAllowed(true);
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
ListSelectionModel rowSelectionModel = table.getSelectionModel();
|
||||
|
||||
rowSelectionModel.addListSelectionListener(e ->{
|
||||
|
||||
//只处理鼠标释放
|
||||
if(e.getValueIsAdjusting()) {
|
||||
return;
|
||||
}
|
||||
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
|
||||
selectedRow = lsm.getMinSelectionIndex();
|
||||
if(selectedRow < 0) {
|
||||
return;
|
||||
}
|
||||
//更新右侧面板内容
|
||||
|
||||
|
||||
|
||||
|
||||
int selectedRow = table.convertRowIndexToModel(e.getFirstIndex());
|
||||
Product p = products.get(selectedRow);
|
||||
String petImage = String.format("/images/%s",p.getImage());
|
||||
ImageIcon icon = new ImageIcon(ProductListFrame.class.getResource(petImage));
|
||||
lblImage.setIcon(icon);
|
||||
|
||||
String descn = p.getDescn();
|
||||
lblDescn.setText("菜品介绍"+ brief);
|
||||
|
||||
double price = p.getPrice();
|
||||
String sprice = String.format("菜品市场价:%.2f",price);
|
||||
lblListprice.setText(sprice);
|
||||
|
||||
double price1 = p.getPrice1();
|
||||
String slblPrice1 = String.format("商品会员价:%.2f",price1);
|
||||
lblUnitcost.setText(slblPrice1);
|
||||
});
|
||||
}else {
|
||||
table.setModel(model);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
//初始化搜索面板
|
||||
private JPanel getSearchPanel() {
|
||||
|
||||
JPanel searchPanel = new JPanel();
|
||||
FlowLayout flowLayout = (FlowLayout) searchPanel.getLayout();
|
||||
flowLayout.setVgap(20);
|
||||
flowLayout.setHgap(40);
|
||||
|
||||
JLabel lbl = new JLabel("请选择菜类别:");
|
||||
lbl.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
searchPanel.add(lbl);
|
||||
|
||||
String[] categorys= {"荤菜","素菜"};
|
||||
|
||||
JComboBox comboBox = new JComboBox(categorys);
|
||||
comboBox.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
searchPanel.add(comboBox);
|
||||
|
||||
JButton btnGo = new JButton("查询");
|
||||
btnGo.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
||||
searchPanel.add(btnGo);
|
||||
|
||||
JButton btnReset = new JButton("重置");
|
||||
btnReset.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
searchPanel.add(btnReset);
|
||||
|
||||
|
||||
//注册查询按钮的ActionEvent事件监听器
|
||||
btnGo.addActionListener(e ->{
|
||||
//所选择的类别
|
||||
String category = (String) comboBox.getSelectedItem();
|
||||
//按照类别查询
|
||||
products = pdao.findCategory(category);
|
||||
ProductTableModel model = new ProductTableModel(products);
|
||||
table.setModel(model);
|
||||
});
|
||||
// 注册重置按钮的ActionEvent事件监听器
|
||||
btnReset.addActionListener(e -> {
|
||||
products = pdao.findAll();
|
||||
ProductTableModel model = new ProductTableModel(products);
|
||||
table.setModel(model);
|
||||
});
|
||||
|
||||
|
||||
return searchPanel;
|
||||
|
||||
|
||||
}}
|
@ -0,0 +1,81 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
public class RRegisterTableModelmbz extends MyFrame {
|
||||
|
||||
|
||||
private RiderLoginFramembz DAO;
|
||||
private JTextField textRiderid;
|
||||
private JPasswordField textPassword;
|
||||
public RRegisterTableModelmbz(String title, int width, int heigth) {
|
||||
super("骑手注册",400,300);
|
||||
this.tubiao();
|
||||
//设置布局管理器为null
|
||||
getContentPane().setLayout(null);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("账号:");
|
||||
lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
lblNewLabel.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
lblNewLabel.setBounds(50, 60, 58, 20);
|
||||
getContentPane().add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("密码:");
|
||||
lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
lblNewLabel_1.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
lblNewLabel_1.setBounds(50, 105, 58, 20);
|
||||
getContentPane().add(lblNewLabel_1);
|
||||
|
||||
textRiderid = new JTextField();
|
||||
textRiderid.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
textRiderid.setBounds(120, 60, 200, 26);
|
||||
getContentPane().add(textRiderid);
|
||||
textRiderid.setColumns(10);
|
||||
|
||||
textPassword = new JPasswordField();
|
||||
textPassword.setColumns(10);
|
||||
textPassword.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
textPassword.setBounds(120, 105, 200, 26);
|
||||
getContentPane().add(textPassword);
|
||||
|
||||
JButton btnOK = new JButton("确定");
|
||||
btnOK.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
btnOK.setBounds(80, 160, 97, 23);
|
||||
getContentPane().add(btnOK);
|
||||
|
||||
JButton btnCancel = new JButton("返回");
|
||||
btnCancel.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
btnCancel.setBounds(220, 160, 97, 23);
|
||||
getContentPane().add(btnCancel);
|
||||
|
||||
//注册btnOK的的ActionEvent事件监听器
|
||||
btnOK.addActionListener(e->{
|
||||
|
||||
System.out.println("注册成功。");
|
||||
JOptionPane.showMessageDialog(null,"注册成功","Title",JOptionPane.PLAIN_MESSAGE);
|
||||
|
||||
RiderLoginFramembz frame = new RiderLoginFramembz();
|
||||
frame.setVisible(true);
|
||||
setVisible(false);
|
||||
});
|
||||
|
||||
//注册btnCancel的ActionEvent事件监听器
|
||||
btnCancel.addActionListener(e-> {
|
||||
//退出系统
|
||||
RiderLoginFramembz frame = new RiderLoginFramembz();
|
||||
frame.setVisible(true);
|
||||
setVisible(false);
|
||||
});
|
||||
}
|
||||
public void tubiao() {
|
||||
MyFrame.setTitleImage(this,"e39b4ce2ebe83d39adabb339c23a1e0.png" );
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package view;
|
||||
|
||||
import java.awt.Font;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import dao.AccountDAOzzy;
|
||||
import dao.RiderDAOmbz;
|
||||
import dao.impl.AccountDaoImplzzy;
|
||||
import dao.impl.RiderDaoImplmbz;
|
||||
import domain.Accountzzy;
|
||||
import domain.Ridermbz;
|
||||
|
||||
public class RiderLoginFramembz extends MyFrame{
|
||||
|
||||
private JTextField txtRiderId;
|
||||
private JPasswordField txtPassword;
|
||||
private JPasswordField txtpassword;
|
||||
|
||||
//String title, int width, int height
|
||||
public RiderLoginFramembz() {
|
||||
super("骑手登录",400,230);//title, width, height);
|
||||
this.tubiao();
|
||||
// TODO 自动生成的构造函数存根
|
||||
getContentPane().setLayout(null);
|
||||
|
||||
JLabel label1=new JLabel();
|
||||
label1.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
label1.setBounds(51, 33, 83, 30);
|
||||
label1.setText("账户:");
|
||||
label1.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
getContentPane().add(label1);
|
||||
|
||||
txtRiderId=new JTextField(10);
|
||||
txtRiderId.setText("");
|
||||
txtRiderId.setBounds(158, 33, 157, 30);
|
||||
txtRiderId.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
getContentPane().add(txtRiderId);
|
||||
|
||||
JLabel label2=new JLabel();
|
||||
label2.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
label2.setBounds(51, 85, 83, 30);
|
||||
label2.setText("密码:");
|
||||
label2.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
getContentPane().add(label2);
|
||||
|
||||
txtpassword=new JPasswordField(10);
|
||||
txtpassword.setText("");
|
||||
txtpassword.setBounds(158, 85, 157, 30);
|
||||
txtpassword.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
getContentPane().add(txtpassword);
|
||||
|
||||
JButton btnOK =new JButton();
|
||||
btnOK.setText("确定");
|
||||
btnOK.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
btnOK.setBounds(140, 140, 100, 30);
|
||||
getContentPane().add(btnOK);
|
||||
|
||||
JButton btnCR = new JButton("注册");
|
||||
btnCR.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 15));
|
||||
btnCR.setBounds(30, 140, 100, 30);
|
||||
getContentPane().add(btnCR);
|
||||
|
||||
JButton btnCancel =new JButton();
|
||||
btnCancel.setText("取消");
|
||||
btnCancel.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
btnCancel.setBounds(255, 140, 100, 30);
|
||||
getContentPane().add(btnCancel);
|
||||
|
||||
//注册btnOK的的ActionEvent事件监听器
|
||||
btnOK.addActionListener(e->{
|
||||
RiderDAOmbz rid =new RiderDaoImplmbz();
|
||||
Ridermbz ri =rid.findById(txtRiderId.getText());
|
||||
String tpassword = new String(txtpassword.getPassword());
|
||||
if(ri != null && tpassword.equals(ri.getPassword())) {
|
||||
System.out.println("登陆成功!");
|
||||
OrderListFramembz plf = new OrderListFramembz("订单列表", 1000, 700);
|
||||
plf.setVisible(true);
|
||||
setVisible(false);
|
||||
MainApp.rider=ri;
|
||||
}else {
|
||||
JLabel label3=new JLabel("您输入的账户或密码有误,请重新输入!");
|
||||
label3.setFont(new Font("微软雅黑",Font.PLAIN,15));
|
||||
JOptionPane.showMessageDialog(null, label3,"登录失败",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
//注册btnCR的的ActionEvent事件监听器
|
||||
btnCR.addActionListener(e->{
|
||||
|
||||
RRegisterTableModelmbz plf = new RRegisterTableModelmbz("骑手注册",800,600);
|
||||
plf.setVisible(true);
|
||||
setVisible(false);
|
||||
|
||||
});
|
||||
|
||||
//注册btnCancel的ActionEvent事件监听器
|
||||
btnCancel.addActionListener(e->{
|
||||
System.exit(0);
|
||||
});
|
||||
|
||||
}
|
||||
public void tubiao() {
|
||||
MyFrame.setTitleImage(this,"e39b4ce2ebe83d39adabb339c23a1e0.png" );
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package view;
|
||||
|
||||
public class WeChatPay extends MyFrame{
|
||||
|
||||
public WeChatPay(String title, int width, int height) {
|
||||
super(title, width, height);
|
||||
// TODO 自动生成的构造函数存根
|
||||
this.tubiao();
|
||||
}
|
||||
|
||||
public void tubiao() {
|
||||
MyFrame.setTitleImage(this,"4.png" );
|
||||
MyFrame.setBackgroundImage(this,"2.jpg");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue