本文主要是介绍Java+Swing+mysql会员卡管理系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Java+Swing+mysql会员卡管理系统
- 一、系统介绍
- 二、功能展示
- 1.主页页面
- 2.会员信息查询
- 3.会员信息删除
- 三、系统实现
- 1.members.java
- 四、其它系统
- 五、获取源码
一、系统介绍
使用 Java 技术开发一个会员卡管理系统,具体实现功能如下: 1. 程序启动显示主界面,点击查询按钮,显示所有会员卡信息;2、输入用户名,可以会员信息进入模糊查询 ;3、选中某行会员卡信息,点击删除按钮,提示是否删除。
二、功能展示
1.主页页面
2.会员信息查询
3.会员信息删除
三、系统实现
1.members.java
package cn.student.view;import java.awt.Dimension;
import java.awt.EventQueue;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;import cn.student.dao.StudentDao;
import cn.student.model.Student;
import cn.student.view.MainPanel;
public class StudentFrame extends JFrame
{ // 定义布局BorderLayout mainLayout = new BorderLayout();CardLayout layout = new CardLayout();JFrame bamFrame;MainPanel mainPanel = new MainPanel();// 主面板JPanel upPanel = new JPanel();// 主面板中的---上面板JPanel downPanel = new JPanel();// 主面板中的---下面板 StudentDao studentdao = new StudentDao();AddStudentPanel addStudentPanel = new AddStudentPanel();//添加课程页面UpdateStudentPanel updateStudentPanel = new UpdateStudentPanel();//添加课程页面final Object[] columnNames = {"学号", "姓名", "性别","学院", "专业", "生日","籍贯", "电话", "邮箱"}; //列名最好用final修饰 Object[][] rowData = queryData("");;DefaultTableModel model = new DefaultTableModel(rowData,columnNames);JTable dataTable = new JTable (model); JScrollPane pane1;JScrollPane pane2;JScrollPane pane3;public StudentFrame() { downPanel.setLayout(layout);//dataTable.setPreferredScrollableViewportSize(new Dimension(650, 100));//设置表格的大小 dataTable.setRowHeight (30);//设置每行的高度为20 dataTable.setRowHeight (0, 20);//设置第1行的高度为15 dataTable.setRowMargin (5);//设置相邻两行单元格的距离 dataTable.setSelectionBackground (Color.white);//设置所选择行的背景色 dataTable.setSelectionForeground (Color.blue);//设置所选择行的前景色 //friends.setGridColor (Color.black);//设置网格线的颜色 dataTable.selectAll ();//选择所有行 //dataTable.setRowSelectionInterval (1,2);//设置初始的选择行,这里是1到3行都处于选择状态 dataTable.clearSelection ();//取消选择 dataTable.setDragEnabled (false);//不懂这个 dataTable.setShowGrid (false);//是否显示网格线 dataTable.setShowHorizontalLines (false);//是否显示水平的网格线 dataTable.setShowVerticalLines (true);//是否显示垂直的网格线 //friends.setValueAt ("tt", 0, 0);//设置某个单元格的值,这个值是一个对象 dataTable.doLayout (); dataTable.setBackground (Color.lightGray); // 设置表格中的数据居中显示DefaultTableCellRenderer r=new DefaultTableCellRenderer();r.setHorizontalAlignment(JLabel.CENTER);dataTable.setDefaultRenderer(Object.class,r);pane1 = new JScrollPane (addStudentPanel);//JTable最好加在JScrollPane上pane1.setPreferredSize(new Dimension (900,500));pane2 = new JScrollPane (updateStudentPanel);//JTable最好加在JScrollPane上pane2.setPreferredSize(new Dimension (900,500));//JScrollPane pane2 = new JScrollPane (example2); pane3 = new JScrollPane (dataTable); pane3.setPreferredSize(new Dimension (900,500));downPanel.add("cardSelect", pane3);// 卡片一 (查询)downPanel.add("cardUpdate", pane2);// 卡片一 (修改)downPanel.add("cardAdd", pane1);// 卡片一 (添加)upPanel.add(mainPanel);//downPanel.add(addCoursePanel);//downPanel.add(pane1);// 定义主窗体bamFrame = new JFrame("学生信息管理系统");bamFrame.setLayout(mainLayout);bamFrame.setSize(1050, 600);// 设定窗体大小// 给窗体加面板bamFrame.add(upPanel, BorderLayout.NORTH);bamFrame.add(downPanel, BorderLayout.SOUTH);addListeners();// 调用监听方法bamFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//bamFrame.pack();bamFrame.setVisible(true);//设置窗口居中bamFrame.setLocationRelativeTo(null);}// 窗体中部分对象监听方法private void addListeners() {// 查询按钮mainPanel.getSelectButton().addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {String cname = mainPanel.getsnoField().getText();System.out.print(cname);Object[][] rowData2 = queryData(cname);model.setDataVector(rowData2, columnNames);layout.show(downPanel, "cardSelect");}});// 添加按钮mainPanel.getAddButton().addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {layout.show(downPanel, "cardAdd");}});// 添加按钮mainPanel.getUpdateButton().addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {int i = dataTable.getSelectedRow();if(i>=0) {String sno = (String) dataTable.getValueAt(i, 0);String name = (String) dataTable.getValueAt(i, 1);String sex = (String) dataTable.getValueAt(i, 2);String school = (String) dataTable.getValueAt(i, 3);String professional = (String) dataTable.getValueAt(i, 4);String birthday = (String) dataTable.getValueAt(i, 5);String address = (String) dataTable.getValueAt(i, 6);String tel = (String) dataTable.getValueAt(i, 7);String email = (String) dataTable.getValueAt(i, 8);updateStudentPanel.getSnoText().setText(sno);updateStudentPanel.getNameText().setText(name);updateStudentPanel.getSexText().setText(sex);updateStudentPanel.getSchoolText().setText(school);updateStudentPanel.getProfessionalText().setText(professional);updateStudentPanel.getBirthdayText().setText(birthday);updateStudentPanel.getAddressText().setText(address);updateStudentPanel.getTelText().setText(tel);updateStudentPanel.getEmailText().setText(email);layout.show(downPanel, "cardUpdate");}else {JOptionPane.showMessageDialog(downPanel, "请选择要修改的学生信息!");return;} }});// 点击《提交》按钮addStudentPanel.getOkButton().addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {String sno = addStudentPanel.getSnoText().getText();String name = addStudentPanel.getNameText().getText();String sex = addStudentPanel.getSexText().getText();String school = addStudentPanel.getSchoolText().getText();String professional = addStudentPanel.getProfessionalText().getText();String birthday = addStudentPanel.getBirthdayText().getText();String address = addStudentPanel.getAddressText().getText();String tel = addStudentPanel.getTelText().getText();String email = addStudentPanel.getEmailText().getText();int i = studentdao.addStudent(sno, name, sex, school, professional, birthday, address, tel, email);if(i>0) {JOptionPane.showMessageDialog(downPanel, "学生信息添加成功!");addStudentPanel.getSnoText().setText("");addStudentPanel.getNameText().setText("");addStudentPanel.getSexText().setText("");addStudentPanel.getSchoolText().setText("");addStudentPanel.getProfessionalText().setText("");addStudentPanel.getBirthdayText().setText("");addStudentPanel.getAddressText().setText("");addStudentPanel.getTelText().setText("");addStudentPanel.getEmailText().setText("");}else{JOptionPane.showMessageDialog(downPanel, "学生信息添加失败!");}}});// 点击《返回》按钮addStudentPanel.getBackButton().addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Object[][] rowData2 = queryData("");model.setDataVector(rowData2, columnNames);layout.show(downPanel, "cardSelect"); }});// 点击《提交》按钮updateStudentPanel.getOkButton().addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {String sno = updateStudentPanel.getSnoText().getText();String name = updateStudentPanel.getNameText().getText();String sex = updateStudentPanel.getSexText().getText();String school = updateStudentPanel.getSchoolText().getText();String professional = updateStudentPanel.getProfessionalText().getText();String birthday = updateStudentPanel.getBirthdayText().getText();String address = updateStudentPanel.getAddressText().getText();String tel = updateStudentPanel.getTelText().getText();String email = updateStudentPanel.getEmailText().getText();int i = studentdao.updateStudent(sno, name, sex, school, professional, birthday, address, tel, email);if(i>0) {JOptionPane.showMessageDialog(downPanel, "学生信息添加成功!");Object[][] rowData2 = queryData("");model.setDataVector(rowData2, columnNames);layout.show(downPanel, "cardSelect");}else{JOptionPane.showMessageDialog(downPanel, "学生信息添加失败!");}}});// 点击《返回》按钮updateStudentPanel.getBackButton().addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Object[][] rowData2 = queryData("");model.setDataVector(rowData2, columnNames);layout.show(downPanel, "cardSelect"); }});// 点击《删除》按钮mainPanel.getDelButton().addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {int i = dataTable.getSelectedRow();if(i>=0) {String sno = (String) dataTable.getValueAt(i, 0);int j=studentdao.DelStudent(sno);;if(j>0) {JOptionPane.showMessageDialog(downPanel, "删除成功!");Object[][] rowData2 = queryData("");model.setDataVector(rowData2, columnNames);}else {JOptionPane.showMessageDialog(downPanel, "删除失败!");Object[][] rowData2 = queryData("");model.setDataVector(rowData2, columnNames);}}else {JOptionPane.showMessageDialog(downPanel, "请选择要删除的信息!");}}});}public static void main(String[] args) {EventQueue.invokeLater(new Runnable() {public void run() {try {StudentFrame frame = new StudentFrame();//frame.setVisible(true);} catch (Exception e) {e.printStackTrace();}}});}//生成表格数据/*** @return*/public Object[][] queryData(String sno){List<Student> list=studentdao.queryStudent(sno);rowData=new Object[list.size()][columnNames.length];for(int i=0;i<list.size();i++){for(int j=0;j<rowData.length;j++){rowData[i][0]=list.get(i).getSno();rowData[i][1]=list.get(i).getName();rowData[i][2]=list.get(i).getSex();rowData[i][3]=list.get(i).getSchool();rowData[i][4]=list.get(i).getProfessional();rowData[i][5]=list.get(i).getBirthday();rowData[i][6]=list.get(i).getAddress();rowData[i][7]=list.get(i).getTel();rowData[i][8]=list.get(i).getEmail();}}return rowData;}
}
四、其它系统
Java+Swing实现学生选课管理系统
Java+Swing实现学校教务管理系统
Java+Swing+sqlserver学生成绩管理系统
Java+Swing用户信息管理系统
Java+Swing实现的五子棋游戏
基于JavaSwing 银行管理系统
Java+Swing+mysql仿QQ聊天工具
Java+Swing 聊天室
Java+Swing+dat文件存储实现学生选课管理系统
Java+Swing可视化图像处理软件
Java+Swing学生信息管理系统
Java+Swing图书管理系统
Java+Swing图书管理系统2.0
基于java+swing+mysql图书管理系统3.0
大作业-基于java+swing+mysql北方传统民居信息管理系统
五、获取源码
点击下载
Java+Swing+mysql会员卡管理系统
这篇关于Java+Swing+mysql会员卡管理系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!