您的位置:首页 > 新闻 > 热点要闻 > Java+Swing学生信息管理系统

Java+Swing学生信息管理系统

2024/12/27 3:35:06 来源:https://blog.csdn.net/python0328/article/details/141883166  浏览:    关键词:Java+Swing学生信息管理系统

Java+Swing学生信息管理系统

  • 一、系统介绍
  • 二、功能展示
    • 1.管理员登陆
    • 2.学生信息查询
    • 3.学生信息添加
    • 4.学生信息修改
    • 5.删除
  • 三、系统实现
    • 1.StudentFrame .java
  • 四、其它
    • 1.其他系统实现

一、系统介绍

该系统实现了管理员系统登陆、学生信息查询、学生信息添加、学生信息修改、学生信息删除。

二、功能展示

1.管理员登陆

在这里插入图片描述

2.学生信息查询

在这里插入图片描述

3.学生信息添加

在这里插入图片描述

4.学生信息修改

在这里插入图片描述

5.删除

在这里插入图片描述

三、系统实现

1.StudentFrame .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;}
}

四、其它

1.其他系统实现

Java+Swing实现学生选课管理系统
Java+Swing图书管理系统

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com