From 9d7b7b3f983cdb44eb32862743786cad59c892bc Mon Sep 17 00:00:00 2001 From: nxist2202005077 <3353492827@qq.com> Date: Sun, 16 Jun 2024 00:25:04 +0800 Subject: [PATCH] ADD file via upload --- SeatListFrame.java | 193 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 SeatListFrame.java diff --git a/SeatListFrame.java b/SeatListFrame.java new file mode 100644 index 0000000..a699d91 --- /dev/null +++ b/SeatListFrame.java @@ -0,0 +1,193 @@ +package com.zn.view; + +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.JOptionPane; +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 com.zn.dao.SeatznDao; +import com.zn.dao.impl.SeatznImpl; +import com.zn.javaBean.Seatzn; + +public class SeatListFrame extends MyFrame{ + + private JTable table; + private JLabel lblImage; + private JLabel lblListprice; + private JLabel lblDescn; + private JLabel lblUnitcost; + + private List Seats=null; + + private SeatznDao pdao =new SeatznImpl(); + private Map cart =new HashMap(); + + private int selectedRow=-1; + + + + + public SeatListFrame(String title, int width, int heigth) { + super(title, width, heigth); + // TODO 自动生成的构造函数存根 + + Seats=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 Component getSearchPanel() { +// // TODO 自动生成的方法存根 +// +// JPanel searchPanel =new JPanel(); +// FlowLayout flowLayout =(FlowLayout)searchPanel.getLayout(); +// flowLayout.setVgap(20); +// flowLayout.setHgap(40); +// +// +// return searchPanel; +// } + + + + private Component getRightPanel() { + // TODO 自动生成的方法存根 + 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)); + + 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("返回上一层"); + btnAdd.setFont(new Font("微软雅黑",Font.PLAIN,15)); + detailPanel.add(btnCheck); + + btnAdd.addActionListener(e->{ + JLabel lf = new JLabel("购票成功"); + lf.setFont(new Font("微软雅黑",Font.PLAIN,15)); + JOptionPane.showMessageDialog(null, lf,"购票成功",JOptionPane.INFORMATION_MESSAGE); //普通提示框 + }); + + btnCheck.addActionListener(e->{ + MovieListFrame plf =new MovieListFrame("电影列表",1000,700); + plf.setVisible(true); + setVisible(false); + + }); + btnAdd.addActionListener(e->{ + if(selectedRow < 0) { + return; + } + Seatzn selectSeat = Seats.get(selectedRow); + String Seatid = selectSeat.getseatidzn(); + + if(cart.containsKey(Seatid)) { + Integer quantity = cart.get(Seatid); + cart.put(Seatid, ++quantity); + }else { + cart.put(Seatid, 1); + } + System.out.println(cart); + }); + btnCheck.addActionListener(e->{ + System.out.println(cart); + }); + + + return rightPanel; + } + + + + + private Component getLeftPanel() { + // TODO 自动生成的方法存根 + JScrollPane leftScrollPane = new JScrollPane(); + leftScrollPane.setViewportView(getTable()); + return leftScrollPane; + } + + + + + private Component getTable() { + // TODO 自动生成的方法存根 + SeatTableModel pmodel = new SeatTableModel(this.Seats); + if(table==null) { + table = new JTable(pmodel); + table.setFont(new Font("微软雅黑",Font.PLAIN,16)); + table.getTableHeader().setFont(new Font("微软雅黑",Font.PLAIN,16)); + table.setRowHeight(51); + 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; + } + + + + + + }); + + }else {table.setModel(pmodel);} + return table; + } + +}