Swing+mysql实现的火车票管理系统1
本系统是一个Swing的火车票管理系统,分为客户和管理员端,普通客户可以预定车票、退款、查看自己的订票列表等,管理员可以对列车、售票员、售票点、列车行程、订单等进行管理。
(文末查看完整源码)
实现功能截图
登录
预定列表
预定记录
修改密码
管理员端:
用户管理
售票员管理
售票点管理
列车管理‘
添加列车
列车行程管理
添加列车行程
订单管理
系统功能
本系统实现了以下功能:
售票端:
1、登录
2、车票预定、预定列表
3、预定记录
4、退款
管理员:
5、用户管理
6、售票员管理
7、售票点管理
8、列车管理
9、列车行程管理
10、订单管理
等
使用技术
数据库:mysql
开发工具:Idea(Myeclispe、Eclipse也可以)
知识点:Swing
项目结构
代码
java端
实体类
Customer.java
package bean;
import java.io.Serializable;
public class Customer implements Serializable{
/**
*
*/
private static final long serialVersionUID = 7883012890434315219L;
private String name;
private int sex;
private String id_num;
private String tel;
private int customer_type;
public static final int SEX_FEMALE = 0;
public static final int SEX_MALE = 1;
public static final int TYPE_STUDENT = 2;
public static final int TYPE_NORMAL = 1;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSex() {
return sex;
}
public String getSexString(){
return sex == SEX_FEMALE ? "女" : "男";
}
public void setSex(int sex) {
this.sex = sex;
}
public String getIdNum() {
return id_num;
}
public void setIdNum(String id_num) {
this.id_num = id_num;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public int getCustomerType() {
return customer_type;
}
public String getCustomerTypeString() {
return customer_type == TYPE_STUDENT ? "学生" : "普通";
}
public void setCustomerType(int customer_type) {
this.customer_type = customer_type;
}
}
Station.java
package bean;
import java.io.Serializable;
public class Station implements Serializable{
/**
*
*/
private static final long serialVersionUID = -5908844098490542228L;
private int station_id;
private String station_name;
public int getStationId() {
return station_id;
}
public void setStationId(int station_id) {
this.station_id = station_id;
}
public String getStationName() {
return station_name;
}
public void setStationName(String station_name) {
this.station_name = station_name;
}
}
dao层
CustomerDAO.java
package dao;
import bean.Customer;
import javax.swing.table.TableModel;
import java.util.List;
public interface CustomerDAO {
void insertCustomer(Customer customer);
void deleteCustomer(Customer customer);
void updateCustomer(Customer customer);
void upsertCustomer(Customer customer);
Customer getCustomerByIdNum(String id_num);
List<Customer> getAllCustomers();
List<Customer> searchCustomers(String key);
}
StationDAO.java
package dao;
import bean.Station;
import javax.swing.table.TableModel;
import java.util.List;
public interface StationDAO {
void insertStation(Station station);
void deleteStation(Station station);
void deleteStation(int station_id);
void updateStation(Station station);
List<Station> getAllStations();
}
frame层
LoginFrame.java
package ui.login;
import javax.swing.*;
import Controller.TrainTicketClient;
import Controller.TrainTicketServer;
import bean.Manager;
import dao.MySQLManager;
import ui.manager.ManagerFrame;
import ui.seller.SellerFrame;
import ui.widget.Measurable;
import ui.widget.XPanel;
import utils.Constants;
import utils.LookUtils;
import utils.StringUtils;
import utils.WidgetUtils;
import java.awt.*;
import java.awt.event.ActionEvent;
public class LoginFrame extends JFrame implements Measurable {
private JTextField usernameField, passwordField;
private JComboBox managerTypeCB = new JComboBox();
public LoginFrame() {
setTitle("登录");
initComponents();
}
private void initComponents() {
XPanel contentPane = new XPanel();
JLabel head = new JLabel("火车票售票系统");
WidgetUtils.format(head, new Font("黑体", Font.PLAIN, 32), SwingConstants.CENTER, SwingConstants.CENTER);
contentPane.addItem(head, 300, 100);
usernameField = contentPane.addHint("用户名");
passwordField = contentPane.addPasswordHint("密码");
managerTypeCB.addItem("管理员");
managerTypeCB.addItem("售票员");
JButton btnLogin = new JButton("登录");
contentPane.addItem(managerTypeCB);
btnLogin.addActionListener(this::onLoginClicked);
contentPane.addItem(btnLogin, 300, 40);
add(contentPane);
}
private void clearPassword() {
passwordField.setText("");
}
private void onLoginClicked(ActionEvent e) {
String username = usernameField.getText();
String password = passwordField.getText();
System.out.println(username+ " " + password);
String error = "未知错误";
if (StringUtils.empty(username)) {
JOptionPane.showMessageDialog(null, "请输入用户名!");
} else if (StringUtils.empty("password")) {
JOptionPane.showMessageDialog(null, "请输入密码!");
} else {
EventQueue.invokeLater(() -> {
if(managerTypeCB.getSelectedItem() == "管理员"){
Manager manager = MySQLManager.getInstance().dao().login(username, password);
Constants.currentManager = manager;
if (manager == null) {
JOptionPane.showMessageDialog(null, "密码错误!");
} else if (Manager.TYPE_SUPERUSER == manager.getManagerType()) {
JOptionPane.showMessageDialog(null, "以管理员身份登陆成功!");
WidgetUtils.popup(ManagerFrame.class);
dispose();
//设置服务器端口号
Thread thread = new Thread(new TrainTicketServer());
thread.start();
} else if (Manager.TYPE_SELLER == manager.getManagerType()){
//WidgetUtils.popup(SellerFrame.class);
JOptionPane.showMessageDialog(null, "身份选择错误!");
}
}else{
//设置服务器端口号
Thread thread = new Thread(new TrainTicketServer());
thread.start();
TrainTicketClient ttc = new TrainTicketClient();
//设置服务器所在的IP及端口号
ttc.connect("localhost", 8888, username, password);
dispose();
}
});
}
}
@Override
public int width() {
return 420;
}
@Override
public int height() {
return 440;
}
public static void main(String[] args) {
LookUtils.beautyEye();
WidgetUtils.popup(LoginFrame.class, EXIT_ON_CLOSE);
}
}
完整源码
觉得有用,记得一键三连哦!