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; } }