用java写一个复杂的学生信息管理系统

时间: 2023-12-26 17:27:07 浏览: 37
为了实现一个复杂的学生信息管理系统,需要考虑以下几个方面: 1. 数据库设计:需要设计一个合适的数据库来存储学生信息,包括学生姓名、学号、班级、课程成绩等信息。 2. 用户登录:需要实现一个登录界面,根据用户输入的用户名和密码来验证用户身份,并根据用户权限跳转到不同的界面。 3. 学生信息管理:需要实现对学生信息的增删改查功能,包括添加学生信息、删除学生信息、修改学生信息和查询学生信息等。 4. 成绩管理:需要实现对学生成绩的管理,包括添加成绩、删除成绩、修改成绩和查询成绩等。 5. 图形化界面:需要使用Java Swing等图形化界面组件来实现一个美观易用的界面,包括表格显示学生信息和成绩信息等。 以下是一个简单的Java学生信息管理系统的代码示例,仅供参考: ```java import java.awt.*; import java.awt.event.*; import java.sql.*; import javax.swing.*; import javax.swing.table.*; public class StudentManagementSystem extends JFrame implements ActionListener { private JLabel titleLabel, nameLabel, idLabel, classLabel, scoreLabel; private JTextField nameField, idField, classField, scoreField; private JButton addButton, deleteButton, updateButton, searchButton; private JTable table; private DefaultTableModel model; public StudentManagementSystem() { super("学生信息管理系统"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); // 标题 titleLabel = new JLabel("学生信息管理系统", JLabel.CENTER); titleLabel.setFont(new Font("宋体", Font.BOLD, 24)); add(titleLabel, BorderLayout.NORTH); // 表格 model = new DefaultTableModel(); model.addColumn("姓名"); model.addColumn("学号"); model.addColumn("班级"); model.addColumn("成绩"); table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane, BorderLayout.CENTER); // 输入框和按钮 JPanel inputPanel = new JPanel(new GridLayout(5, 2)); nameLabel = new JLabel("姓名:"); nameField = new JTextField(); idLabel = new JLabel("学号:"); idField = new JTextField(); classLabel = new JLabel("班级:"); classField = new JTextField(); scoreLabel = new JLabel("成绩:"); scoreField = new JTextField(); addButton = new JButton("添加"); addButton.addActionListener(this); deleteButton = new JButton("删除"); deleteButton.addActionListener(this); updateButton = new JButton("修改"); updateButton.addActionListener(this); searchButton = new JButton("查询"); searchButton.addActionListener(this); inputPanel.add(nameLabel); inputPanel.add(nameField); inputPanel.add(idLabel); inputPanel.add(idField); inputPanel.add(classLabel); inputPanel.add(classField); inputPanel.add(scoreLabel); inputPanel.add(scoreField); inputPanel.add(addButton); inputPanel.add(deleteButton); inputPanel.add(updateButton); inputPanel.add(searchButton); add(inputPanel, BorderLayout.SOUTH); // 窗口大小和位置 setSize(600, 400); setLocationRelativeTo(null); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource() == addButton) { // 添加学生信息 String name = nameField.getText(); String id = idField.getText(); String className = classField.getText(); String score = scoreField.getText(); if (name.equals("") || id.equals("") || className.equals("") || score.equals("")) { JOptionPane.showMessageDialog(this, "请输入完整信息"); return; } try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "123456"); Statement stmt = conn.createStatement(); String sql = "INSERT INTO student_info (name, id, class, score) VALUES ('" + name + "', '" + id + "', '" + className + "', '" + score + "')"; stmt.executeUpdate(sql); stmt.close(); conn.close(); JOptionPane.showMessageDialog(this, "添加成功"); nameField.setText(""); idField.setText(""); classField.setText(""); scoreField.setText(""); updateTable(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(this, "添加失败"); } } else if (e.getSource() == deleteButton) { // 删除学生信息 int row = table.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(this, "请选择要删除的行"); return; } String id = (String) model.getValueAt(row, 1); try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "123456"); Statement stmt = conn.createStatement(); String sql = "DELETE FROM student_info WHERE id='" + id + "'"; stmt.executeUpdate(sql); stmt.close(); conn.close(); JOptionPane.showMessageDialog(this, "删除成功"); updateTable(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(this, "删除失败"); } } else if (e.getSource() == updateButton) { // 修改学生信息 int row = table.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(this, "请选择要修改的行"); return; } String id = (String) model.getValueAt(row, 1); String name = nameField.getText(); String className = classField.getText(); String score = scoreField.getText(); if (name.equals("") || className.equals("") || score.equals("")) { JOptionPane.showMessageDialog(this, "请输入完整信息"); return; } try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "123456"); Statement stmt = conn.createStatement(); String sql = "UPDATE student_info SET name='" + name + "', class='" + className + "', score='" + score + "' WHERE id='" + id + "'"; stmt.executeUpdate(sql); stmt.close(); conn.close(); JOptionPane.showMessageDialog(this, "修改成功"); nameField.setText(""); idField.setText(""); classField.setText(""); scoreField.setText(""); updateTable(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(this, "修改失败"); } } else if (e.getSource() == searchButton) { // 查询学生信息 String id = idField.getText(); try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "123456"); Statement stmt = conn.createStatement(); String sql = "SELECT * FROM student_info WHERE id='" + id + "'"; ResultSet rs = stmt.executeQuery(sql); if (rs.next()) { nameField.setText(rs.getString("name")); classField.setText(rs.getString("class")); scoreField.setText(rs.getString("score")); } else { JOptionPane.showMessageDialog(this, "未找到该学生信息"); } rs.close(); stmt.close(); conn.close(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(this, "查询失败"); } } } private void updateTable() { // 更新表格数据 model.setRowCount(0); try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "123456"); Statement stmt = conn.createStatement(); String sql = "SELECT * FROM student_info"; ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { String name = rs.getString("name"); String id = rs.getString("id"); String className = rs.getString("class"); String score = rs.getString("score"); model.addRow(new Object[] { name, id, className, score }); } rs.close(); stmt.close(); conn.close(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(this, "更新表格失败"); } } public static void main(String[] args) { new StudentManagementSystem(); } } ```

相关推荐

最新推荐

recommend-type

java面向对象之学生信息管理系统

主要为大家详细介绍了java面向对象之学生信息管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

java(swing)+ mysql实现学生信息管理系统

主要分享了java mysql实现学生信息管理系统的源码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

Java学生信息管理系统设计(数据库版)

主要为大家详细介绍了数据库版的Java学生信息管理系统设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

java实现简单的学生信息管理系统代码实例

主要介绍了java实现简单的学生信息管理系统,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。