Compare commits

...

6 Commits
seat ... movie

@ -0,0 +1,125 @@
package com.tmj.view;
import java.awt.Component;
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 com.tmj.dao.impl.AccounttmjImpl;
import com.tmj.dao.impl.MovietmjImpl;
import com.tmj.javaBean.Accounttmj;
import com.tmj.javaBean.Movietmj;
public class AddMovie extends MyFrame{
private JTextField txtCategory;
private JTextField txtProductid;
private JTextField txtCname;
private JTextField txtEname;
public AddMovie(String title, int width, int heigth) {
super(title, width, heigth);
getContentPane().setLayout(null);
JLabel categoryLabel=new JLabel();
categoryLabel.setHorizontalAlignment(SwingConstants.RIGHT);
categoryLabel.setBounds(51,33,83,30);
categoryLabel.setText("电影类型");
categoryLabel.setFont(new Font("微软雅黑",Font.PLAIN,15));
getContentPane().add(categoryLabel);
txtCategory =new JTextField(10);
txtCategory.setText("电影类型");
txtCategory.setBounds(158,33,157,30);
txtCategory.setFont(new Font("微软雅黑",Font.PLAIN,15));
getContentPane().add(txtCategory);
JLabel productidLabel=new JLabel();
productidLabel.setHorizontalAlignment(SwingConstants.RIGHT);
productidLabel.setBounds(51,66,83,30);
productidLabel.setText("电影编号");
productidLabel.setFont(new Font("微软雅黑",Font.PLAIN,15));
getContentPane().add(productidLabel);
txtProductid =new JTextField(10);
txtProductid.setText("电影编号");
txtProductid.setBounds(158,66,157,30);
txtProductid.setFont(new Font("微软雅黑",Font.PLAIN,15));
getContentPane().add(txtProductid);
JLabel cnameLabel=new JLabel();
cnameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
cnameLabel.setBounds(51,99,83,30);
cnameLabel.setText("电影中文名");
cnameLabel.setFont(new Font("微软雅黑",Font.PLAIN,15));
getContentPane().add(cnameLabel);
txtCname =new JTextField(10);
txtCname.setText("电影中文名");
txtCname.setBounds(158,99,157,30);
txtCname.setFont(new Font("微软雅黑",Font.PLAIN,15));
getContentPane().add(txtCname);
JLabel enameLabel=new JLabel();
enameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
enameLabel.setBounds(51,132,83,30);
enameLabel.setText("电影英文名");
enameLabel.setFont(new Font("微软雅黑",Font.PLAIN,15));
getContentPane().add(enameLabel);
txtEname =new JTextField(10);
txtEname.setText("电影英文名");
txtEname.setBounds(158,132,157,30);
txtEname.setFont(new Font("微软雅黑",Font.PLAIN,15));
getContentPane().add(txtEname);
JButton btnadd = new JButton();
btnadd.setText("添加");
btnadd.setFont(new Font("微软雅黑",Font.PLAIN,15));
btnadd.setBounds(61,200,100,30);
getContentPane().add(btnadd);
JButton btnCancel = new JButton();
btnCancel.setText("返回上一层");
btnCancel.setFont(new Font("微软雅黑",Font.PLAIN,15));
btnCancel.setBounds(225,200,100,30);
getContentPane().add(btnCancel);
btnadd.addActionListener(e->{
JLabel lf = new JLabel("添加成功");
lf.setFont(new Font("微软雅黑",Font.PLAIN,15));
JOptionPane.showMessageDialog(null, lf,"购票成功",JOptionPane.INFORMATION_MESSAGE);
String category=txtCategory.getText();
String movied=txtProductid.getText();
String cname=txtCname.getText();
String ename=txtEname.getText();
double sss=1;
double yyy=1;
Movietmj a2tmj=new Movietmj(category,movied,cname,ename,"images/img.jpg","1",sss,yyy);
MovietmjImpl actmj=new MovietmjImpl();
actmj.insert(a2tmj);
});
btnCancel.addActionListener(e->{
MovieListFrame plf =new MovieListFrame("电影列表",1000,700);
plf.setVisible(true);
setVisible(false);
});
}
}

@ -0,0 +1,273 @@
package com.tmj.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.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.tmj.dao.MovietmjDao;
import com.tmj.dao.impl.MovietmjImpl;
import com.tmj.javaBean.Movietmj;
public class MovieListFrame extends MyFrame{
private JTable table;
private JLabel lblImage;
private JLabel lblPrice;
private JLabel lblDescn;
private JLabel lblScore;
private List<Movietmj> movies=null;
private MovietmjDao pdao =new MovietmjImpl();
private Map<String,Integer> cart =new HashMap<String,Integer>();
private int selectedRow=-1;
public MovieListFrame(String title, int width, int heigth) {
super(title, width, heigth);
// TODO 自动生成的构造函数存根
movies=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);
JButton btnadd = new JButton("添加");
btnadd.setFont(new Font("微软雅黑",Font.PLAIN,15));
searchPanel.add(btnadd);
btnadd.addActionListener(e->{
AddMovie aaa =new AddMovie("电影添加",500,355);
aaa.setVisible(true);
setVisible(false);
});
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 btnsearch = new JButton("查询");
btnsearch.setFont(new Font("微软雅黑",Font.PLAIN,15));
searchPanel.add(btnsearch);
JButton btnreset = new JButton("重置");
btnsearch.setFont(new Font("微软雅黑",Font.PLAIN,15));
searchPanel.add(btnreset);
btnsearch.addActionListener(e->{
String movieidtmj =(String)comboBox.getSelectedItem();
movies = pdao.findByMovieidtmj(movieidtmj);
MovieTableModel pmodel = new MovieTableModel(movies);
table.setModel(pmodel);
});
btnreset.addActionListener(e->{
movies = pdao.findAll();
MovieTableModel pmodel = new MovieTableModel(movies);
table.setModel(pmodel);
});
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));
JSeparator separator1 = new JSeparator(); //分割线
detailPanel.add(separator1);
lblPrice = new JLabel();
detailPanel.add(lblPrice);
lblPrice.setFont(new Font("微软雅黑",Font.PLAIN,16));//成本
lblScore = new JLabel();
detailPanel.add(lblScore);
lblScore.setFont(new Font("微软雅黑",Font.PLAIN,16));//单价
lblDescn = new JLabel();
detailPanel.add(lblDescn);
lblDescn.setFont(new Font("微软雅黑",Font.PLAIN,16)); //详情
JSeparator separator2 = new JSeparator(); //分割线2
detailPanel.add(separator2);
JButton btnAdd = new JButton("购票");
btnAdd.setFont(new Font("微软雅黑",Font.PLAIN,15));
detailPanel.add(btnAdd);
btnAdd.addActionListener(e->{
SeatListFrame aaa =new SeatListFrame("票列表",1000,700);
aaa.setVisible(true);
setVisible(false);
});
JLabel lb1 = new JLabel();
detailPanel.add(lb1);
JButton btnCheck = new JButton("返回登陆界面");
btnAdd.setFont(new Font("微软雅黑",Font.PLAIN,15));
detailPanel.add(btnCheck);
btnAdd.addActionListener(e->{
if(selectedRow < 0) {
return;
}
Movietmj selectMovie = movies.get(selectedRow);
String movieid = selectMovie.getmovieidtmj();
if(cart.containsKey(movieid)) {
Integer quantity = cart.get(movieid);
cart.put(movieid, ++quantity);
}else {
cart.put(movieid, 1);
}
System.out.println(cart);
});
btnCheck.addActionListener(e->{
System.out.println(cart);
LoginFrame aaa =new LoginFrame("用户登录",400,255);
aaa.setVisible(true);
setVisible(false);
});
return rightPanel;
}
private Component getLeftPanel() {
// TODO 自动生成的方法存根
JScrollPane leftScrollPane = new JScrollPane();
leftScrollPane.setViewportView(getTable());
return leftScrollPane;
}
private Component getTable() {
// TODO 自动生成的方法存根
MovieTableModel pmodel = new MovieTableModel(this.movies);
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;
}
Movietmj p = movies.get(selectedRow);
String petImage = String.format("/images/%s", p.getimagetmj());
System.out.println(petImage);
ImageIcon icon = new ImageIcon(MovieListFrame.class.getResource(petImage));
lblImage.setIcon(icon);
String descn=p.getdescntmj();
lblDescn.setText("电影简介:"+descn);
Double price =p.getpricetmj();
String sprice = String.format("电影票价:%.2f", price);
lblPrice.setText(sprice);
Double score = p.getscoretmj();
String sscore = String.format("电影评分:%.2f", score);
lblScore.setText(sscore);
});
}else {table.setModel(pmodel);}
return table;
}
}

@ -0,0 +1,52 @@
package com.tmj.view;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import com.tmj.javaBean.Movietmj;
public class MovieTableModel extends AbstractTableModel{
private String[] columnNames= {"电影类型","电影编号","电影中文名","电影英文名"};
private List<Movietmj> movies=null;
public MovieTableModel(List<Movietmj> movies) {
this.movies=movies;
}
@Override
public int getRowCount() {
// TODO 自动生成的方法存根
return movies.size();
}
@Override
public int getColumnCount() {
// TODO 自动生成的方法存根
return columnNames.length;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
// TODO 自动生成的方法存根
Movietmj p=movies.get(rowIndex);
switch(columnIndex) {
case 0:
return p.getmovieidtmj();
case 1:
return p.getcategorytmj();
case 2:
return p.getcnametmj();
default:
return p.getenametmj();
}
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
}

@ -0,0 +1,80 @@
package com.tmj.javaBean;
public class Movietmj {
String movieidtmj;
String categorytmj;
String enametmj;
String cnametmj;
String imagetmj;
String descntmj;
Double pricetmj;
Double scoretmj;
public Movietmj() {
}
public Movietmj(String movieidtmj,String categorytmj,String enametmj,String cnametmj,String imagetmj,String descntmj,Double pricetmj,Double scoretmj){
this.movieidtmj=movieidtmj;
this.categorytmj=categorytmj;
this.enametmj=enametmj;
this.cnametmj=cnametmj;
this.imagetmj=imagetmj;
this.descntmj=descntmj;
this.pricetmj=pricetmj;
this.scoretmj=scoretmj;
}
public String getmovieidtmj(){
return movieidtmj;
}
public void setmovieidtmj(String movieidtmj){
this.movieidtmj=movieidtmj;
}
public String getcategorytmj(){
return categorytmj;
}
public void setcategorytmj(String categorytmj){
this.categorytmj=categorytmj;
}
public String getenametmj(){
return enametmj;
}
public void setenametmj(String enametmj){
this.enametmj=enametmj;
}
public String getimagetmj(){
return imagetmj;
}
public void setimagetmj(String imagetmj){
this.imagetmj=imagetmj;
}
public String getcnametmj(){
return cnametmj;
}
public void setcnametmj(String cnametmj){
this.cnametmj=cnametmj;
}
public String getdescntmj(){
return descntmj;
}
public void setdescntmj(String descntmj){
this.descntmj=descntmj;
}
public Double getpricetmj(){
return pricetmj;
}
public void setpricetmj(Double pricetmj){
this.pricetmj=pricetmj;
}
public Double getscoretmj(){
return scoretmj;
}
public void setscoretmj(Double scoretmj){
this.scoretmj=scoretmj;
}
@Override
public String toString() {
return "Movietmj [movieidtmj=" + movieidtmj + ", categorytmj=" + categorytmj + ", enametmj=" + enametmj
+ ", cnametmj=" + cnametmj + ", imagetmj=" + imagetmj + ", descntmj=" + descntmj + ", pricetmj="
+ pricetmj + ", scoretmj=" + scoretmj + "]";
}
}

@ -0,0 +1,13 @@
package com.tmj.dao;
import java.util.ArrayList;
import java.util.List;
import com.tmj.javaBean.*;
public interface MovietmjDao {
public List<Movietmj> findByMovieidtmj(String movieidtmj);
public void insert(Movietmj movietmj);
public ArrayList<Movietmj> findAll();
public int updateMovietmj(Movietmj movietmj);
public int deleteMovietmj(String movieidtmj);
}

@ -0,0 +1,175 @@
package com.tmj.dao.impl;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.tmj.dao.MovietmjDao;
import com.tmj.javaBean.Movietmj;
public class MovietmjImpl implements MovietmjDao {
@Override
public List<Movietmj> findByMovieidtmj(String movieidtmj) {
// TODO 自动生成的方法存根
List<Movietmj> pttmj = new ArrayList<Movietmj>();
try {
Connection conntmj = JDBCUtil.getConnection();
String sqltmj ="select *from movie where movieid=?";
PreparedStatement prestmtmj=conntmj.prepareStatement(sqltmj);
prestmtmj.setString(1,movieidtmj);
ResultSet rstmj=prestmtmj.executeQuery();
while(rstmj.next()) {
Movietmj movie=new Movietmj();
movie.setmovieidtmj(rstmj.getString("movieid"));
movie.setcategorytmj(rstmj.getString("category"));
movie.setcnametmj(rstmj.getString("cname"));
movie.setenametmj(rstmj.getString("ename"));
movie.setimagetmj(rstmj.getString("image"));
movie.setdescntmj(rstmj.getString("descn"));
movie.setpricetmj(rstmj.getDouble("price"));
movie.setscoretmj(rstmj.getDouble("score"));
pttmj.add(movie);
}
rstmj.close();
prestmtmj.close();
conntmj.close();
}
catch(Exception e) {
e.printStackTrace();
}
return pttmj;
}
@Override
public void insert(Movietmj movietmj) {
// TODO 自动生成的方法存根
try {
Connection conntmj = JDBCUtil.getConnection();
String sqltmj ="Insert into movie (movieid,category,cname,ename,image,descn,price,score) values(?,?,?,?,?,?,?,?)";
PreparedStatement prestmtmj=conntmj.prepareStatement(sqltmj);
prestmtmj.setString(1,movietmj.getmovieidtmj());
prestmtmj.setString(2,movietmj.getcategorytmj());
prestmtmj.setString(3,movietmj.getenametmj());
prestmtmj.setString(4,movietmj.getcnametmj());
prestmtmj.setString(5,movietmj.getimagetmj());
prestmtmj.setString(6,movietmj.getdescntmj());
prestmtmj.setDouble(7,movietmj.getpricetmj());
prestmtmj.setDouble(8,movietmj.getscoretmj());
prestmtmj.executeUpdate();
prestmtmj.close();
conntmj.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
@Override
public ArrayList<Movietmj> findAll() {
ArrayList<Movietmj> movies=new ArrayList<Movietmj>();
try {
Connection conntmj = JDBCUtil.getConnection();
String sql ="select *from movie";
Statement sts =conntmj.createStatement();
ResultSet rs=sts.executeQuery(sql);
while(rs.next()) {
Movietmj movie=new Movietmj();
movie.setmovieidtmj(rs.getString("movieid"));
movie.setcategorytmj(rs.getString("category"));
movie.setcnametmj(rs.getString("cname"));
movie.setenametmj(rs.getString("ename"));
movie.setimagetmj(rs.getString("image"));
movie.setdescntmj(rs.getString("descn"));
movie.setpricetmj(rs.getDouble("price"));
movie.setscoretmj(rs.getDouble("score"));
movies.add(movie);
}
rs.close();
sts.close();
conntmj.close();
}
catch(Exception e) {
e.printStackTrace();
}
// TODO 自动生成的方法存根
return movies;
}
@Override
public int updateMovietmj(Movietmj movietmj) {
// TODO 自动生成的方法存根
try {
Connection conntmj = JDBCUtil.getConnection();
String sqltmj ="update movie set ename=?,cname=?,category=? where movieid=?";
PreparedStatement prestmtmj=conntmj.prepareStatement(sqltmj);
prestmtmj.setString(4,movietmj.getmovieidtmj());
prestmtmj.setString(3,movietmj.getcategorytmj());
prestmtmj.setString(1,movietmj.getenametmj());
prestmtmj.setString(2,movietmj.getcnametmj());
prestmtmj.executeUpdate();
prestmtmj.close();
conntmj.close();
}
catch(Exception e) {
e.printStackTrace();
}
return 0;
}
@Override
public int deleteMovietmj(String movieidtmj) {
int flagtmj=0;
// TODO 自动生成的方法存根
try {
Connection conntmj = JDBCUtil.getConnection();
String sqltmj ="delete from movie where movieid=?";
PreparedStatement prestmtmj=conntmj.prepareStatement(sqltmj);
prestmtmj.setString(1,movieidtmj);
flagtmj = prestmtmj.executeUpdate();
prestmtmj.close();
conntmj.close();
}
catch(Exception e) {
e.printStackTrace();
}
return flagtmj;
}
public static void main(String[] args) {
MovietmjImpl actmj =new MovietmjImpl();
for(Movietmj al : actmj.findAll()) {
System.out.print(al);
System.out.println("");
System.out.println("---------------------------");
}
System.out.println(actmj.findByMovieidtmj("1"));
System.out.println("---------------------------");
Movietmj a1tmj=new Movietmj();
actmj.updateMovietmj(a1tmj);
for(Movietmj al : actmj.findAll()) {
System.out.print(al);
System.out.println("");
System.out.println("---------------------------");
}
System.out.println(actmj.deleteMovietmj("2"));
System.out.println("---------------------------");
for(Movietmj al : actmj.findAll()) {
System.out.print(al);
System.out.println("");
System.out.println("---------------------------");
}
Movietmj a2tmj=new Movietmj();
actmj.insert(a2tmj);
for(Movietmj al : actmj.findAll()) {
System.out.print(al);
System.out.println("");
System.out.println("---------------------------");
}
}
}
Loading…
Cancel
Save