mysql订票信息管理_Java Swing+Mysql电影购票系统(普通用户/管理员登录+充值购票+影院管理)...

本文介绍了一个使用Java Swing和MySQL构建的电影购票系统,包括普通用户和管理员登录、充值购票、影院信息管理等功能。系统实现了在线选座、数据库连接、增删改查操作,并提供了登录页面和管理员页面的详细设计。
摘要由CSDN通过智能技术生成

@

文章目录

电影购票系统模拟真实购票流程,在线选座,充值购票,影院信息管理。登录用户分为:普通用户+管理员

数据库连接

BaseDao类,建立数据库连接

代码如下:

package daoimpl;

import java.lang.reflect.Field;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;

public class BaseDao {

private static final String DRIVER = "com.mysql.jdbc.Driver";

private static final String URL = "jdbc:mysql://localhost:3306/moviesystem?useUnicode=true&characterEncoding=UTF-8";

private static final String USER = "root";

private static final String PASSWORD = "123456";

static{

try {

Class.forName(DRIVER);

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

}

/**

* 与数据库建立连接

*

* @return

*/

public static Connection getconn() {

Connection conn = null;

try {

conn = DriverManager.getConnection(URL,USER,PASSWORD);

} catch (SQLException e) {

e.printStackTrace();

}

return conn;

}

/**

* 释放所有资源

*

*/

public static void closeAll(ResultSet rs, PreparedStatement psts, Connection conn) {

try {

if (rs != null) {

rs.close();

}

if (psts != null) {

psts.close();

}

if (conn != null) {

conn.close();

}

} catch (SQLException e) {

e.printStackTrace();

}

}

/**

* 此方法可以完成对数据库的增删改操作

*

* @param sql

* @param params

* @return

*/

public static boolean operUpdata(String sql, List params) {

int res = 0;//返回影响的行数

Connection conn = null;

PreparedStatement psts = null;//执行sql语句

ResultSet rs = null;

try {

conn = getconn();// 与数据库建立连接

psts = conn.prepareStatement(sql);// 装载sql语句

if (params != null) {// 假如有?号,在执行之前把问号替换掉

for(int i = 0; i < params.size(); i++) {

psts.setObject(i + 1, params.get(i));

}

}

res = psts.executeUpdate();

} catch (SQLException e) {

e.printStackTrace();

} finally {

closeAll(rs, psts, conn);

}

return res > 0 ? true : false;

}

/*

* 实现查的操作

*

*/

public static List operQuery(String sql, List p, Class cls)throws Exception {

Connection conn = null;

PreparedStatement pste = null;// 预处理语句

ResultSet rs = null;// 结果集

List list = new ArrayList();

conn = getconn();

try {

pste = conn.prepareStatement(sql);

if (p != null) {// 将条件值装入预处理语句

for (int i = 0; i < p.size(); i++) {

pste.setObject(i + 1, p.get(i));

}

}

rs = pste.executeQuery();// 执行

ResultSetMetaData rsmd = rs.getMetaData();

while (rs.next()) {

T entity = cls.newInstance();// 反射

for (int j = 0; j < rsmd.getColumnCount(); j++) {

// 从数据库中取得字段名

String col_name = rsmd.getColumnName(j + 1);

Object value = rs.getObject(col_name);

Field field = cls.getDeclaredField(col_name);

field.setAccessible(true);// 类中的成员变量为private,故必须进行此操作

field.set(entity, value);// 给实体类entity的field属性赋值

}

list.add(entity);// 加入list列表

}

} catch (SQLException e) {

e.printStackTrace();

} finally {

closeAll(rs, pste, conn);// 关闭连接,释放资源

}

return list;

}

}

主要页面

登录页面:LoginUI

package view;

import java.awt.Color;

import java.awt.Container;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Image;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPasswordField;

import javax.swing.JRadioButton;

import javax.swing.JTextField;

import entity.User;

import service.UserService;

import serviceimpl.UserServiceImpl;

class Login implements ActionListener {

private JFrame jf = new JFrame("电影系统");

private Container con = jf.getContentPane();// 获得面板

private Toolkit toolkit = Toolkit.getDefaultToolkit();

private Dimension sc = toolkit.getScreenSize();// 获得屏幕尺寸

private JLabel title = new JLabel("欢迎使用电影购票系统");

private JLabel name1 = new JLabel("用户名");

private JLabel pass1 = new JLabel("密 码");

private JTextField textName = new JTextField();

private JPasswordField textPs = new JPasswordField();// 密码框

private JRadioButton choice1 = new JRadioButton("用户");

private JRadioButton choice2 = new JRadioButton("管理员");

private JLabel code1 = new JLabel("验证码");

private JTextField textCode = new JTextField();

private JLabel code2 = new JLabel();

private JButton btn_login = new JButton("登录");

private JButton btn_rgist = new JButton("注册");

// 按钮

private Font font = new Font("楷体", 1, 28);

private Font font1 = new Font("楷体", 0, 20);

private Font font2 = new Font("楷体", 0, 18);

// 字体,样式(粗体,斜体),大小

private ButtonGroup buttongroup = new ButtonGroup();

private ImageIcon loginbg = new ImageIcon("image/loginbg.jpg");

public Login() {

con.setLayout(null);

jf.setSize(1000, 618);

jf.setLocation((sc.width - 1000) / 2, (sc.height - 618) / 2);

jf.setResizable(false);// 窗口大小不可变

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

con.setVisible(true);

JLabel maxlabel = new JLabel(loginbg);

title.setBounds(375, 10, 370, 30);

title.setFont(font);

//title.setForeground(Color.black);

title.setForeground(Color.white);

name1.setBounds(140, 140, 85, 30);// 账号的位置大小

name1.setFont(font1);// 字体

name1.setForeground(Color.red);// name1字的颜色

pass1.setBounds(140, 190, 85, 30);// 密码的位置大小

pass1.setForeground(Color.red);

pass1.setFont(font1);

textName.setBounds(200, 143, 140, 25);

textName.setBorder(null);// 边框

textName.setFont(font1);

textPs.setBounds(200, 193, 140, 25);

textPs.setBorder(null);

textPs.setEchoChar('*');// 可以将密码显示为* ;默认为·

textPs.setFont(font1);

choice1.setBounds(140, 290, 120, 25);

choice1.setSelected(true);// 默认普通用户登录

choice2.setBounds(260, 290, 80, 25);

code1.setBounds(140, 240, 60, 25);

code1.setFont(font1);

code1.setForeground(Color.black);

textCode.setBounds(200, 240, 95, 25);

textCode.setBorder(null);

textCode.setFont(font1);

code2.setBounds(300, 240, 70, 25);

code2.setFont(font1);

code2.setText(code());

code2.setForeground(Color.black);

code1.setVisible(false);

code2.setVisible(false);

textCode.setVisible(false);

btn_login.setBounds(140, 340, 90, 25);//140, 340, 90, 25

btn_login.setFont(font2);

btn_login.addActionListener(this);

jf.getRootPane().setDefaultButton(btn_login);//回车默认是登录按钮

btn_rgist.setBounds(250, 340, 90, 25);//250, 340, 90, 25

btn_rgist.setFont(font2);

btn_rgist.addActionListener(this);

JLabel bg = new JLabel(loginbg);

maxlabel.add(title);

maxlabel.add(name1);

maxlabel.add(pass1);

maxlabel.add(textName);

maxlabel.add(textPs);

maxlabel.add(choice1);

maxlabel.add(choice2);

buttongroup.add(choice1);

buttongroup.add(choice2);

maxlabel.add(code1);

maxlabel.add(code2);

maxlabel.add(textCode);

maxlabel.add(btn_login);

maxlabel.add(btn_rgist);

maxlabel.setBounds(0, 0, 999, 617);

con.add(maxlabel);

}

private String code() {

int m = 0;

for (int i = 0; i < 4; i++) {

m *= 10;

m += (int) (Math.random() * 9 + 1);

}

return ((Integer) m).toString();

}

public void cleanUserInfo() {

this.textName.setText("");

this.textPs.setText("");

this.textCode.setText("");

}

public static void winMessage(String str) {// 提示窗口,有多个地方调用

JOptionPane.showMessageDialog(null, str, "提示",

JOptionPane.INFORMATION_MESSAGE);

}<

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值