Java源代码,开发一个简易信息管理软件,要求需求定义清晰,源代码符合规范,设计良好的图形用户界面,方便用户的操作。示例,班级成绩管理系统,管理一个班30人的思政、高数、英语、体育四科的成绩,主要功能有:学生信息管理,各门课成绩管理,成绩统计与排序等。
时间: 2023-12-09 16:03:29 浏览: 101
好的,这是一个比较复杂的项目,需要一定的开发经验和技能。以下是一个简单的班级成绩管理系统的Java源代码示例,供参考:
```java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ScoreManagementSystem extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel lbTitle, lbName, lbGender, lbAge, lbMajor, lbScore;
private JTextField tfName, tfAge, tfMajor, tfScore;
private JRadioButton rbMale, rbFemale;
private ButtonGroup bgGender;
private JButton btnAdd, btnDelete, btnModify, btnClear, btnSearch, btnSort;
private JTextArea taOutput;
private JScrollPane spOutput;
private StudentList studentList;
public ScoreManagementSystem() {
super("班级成绩管理系统");
lbTitle = new JLabel("学生信息管理");
lbTitle.setFont(new Font("宋体", Font.BOLD, 20));
lbName = new JLabel("姓名:");
lbGender = new JLabel("性别:");
lbAge = new JLabel("年龄:");
lbMajor = new JLabel("专业:");
lbScore = new JLabel("成绩:");
tfName = new JTextField(10);
tfAge = new JTextField(10);
tfMajor = new JTextField(10);
tfScore = new JTextField(10);
rbMale = new JRadioButton("男", true);
rbFemale = new JRadioButton("女", false);
bgGender = new ButtonGroup();
bgGender.add(rbMale);
bgGender.add(rbFemale);
btnAdd = new JButton("添加");
btnDelete = new JButton("删除");
btnModify = new JButton("修改");
btnClear = new JButton("清空");
btnSearch = new JButton("搜索");
btnSort = new JButton("排序");
taOutput = new JTextArea(10, 30);
taOutput.setEditable(false);
spOutput = new JScrollPane(taOutput);
studentList = new StudentList();
JPanel pInput = new JPanel(new GridLayout(6, 2));
pInput.add(lbName);
pInput.add(tfName);
pInput.add(lbGender);
pInput.add(rbMale);
pInput.add(new JLabel(""));
pInput.add(rbFemale);
pInput.add(lbAge);
pInput.add(tfAge);
pInput.add(lbMajor);
pInput.add(tfMajor);
pInput.add(lbScore);
pInput.add(tfScore);
JPanel pButton = new JPanel(new GridLayout(2, 3));
pButton.add(btnAdd);
pButton.add(btnDelete);
pButton.add(btnModify);
pButton.add(btnClear);
pButton.add(btnSearch);
pButton.add(btnSort);
JPanel pOutput = new JPanel();
pOutput.add(spOutput);
Container container = getContentPane();
container.setLayout(new BorderLayout());
container.add(lbTitle, BorderLayout.NORTH);
container.add(pInput, BorderLayout.CENTER);
container.add(pButton, BorderLayout.SOUTH);
container.add(pOutput, BorderLayout.EAST);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 400);
setLocationRelativeTo(null);
setVisible(true);
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = tfName.getText();
String gender = rbMale.isSelected() ? "男" : "女";
int age = Integer.parseInt(tfAge.getText());
String major = tfMajor.getText();
double score = Double.parseDouble(tfScore.getText());
Student student = new Student(name, gender, age, major, score);
if (studentList.add(student)) {
taOutput.setText("添加成功!\n" + studentList.toString());
clearInput();
} else {
taOutput.setText("添加失败!\n");
}
}
});
btnDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = tfName.getText();
if (studentList.delete(name)) {
taOutput.setText("删除成功!\n" + studentList.toString());
clearInput();
} else {
taOutput.setText("删除失败!\n");
}
}
});
btnModify.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = tfName.getText();
String gender = rbMale.isSelected() ? "男" : "女";
int age = Integer.parseInt(tfAge.getText());
String major = tfMajor.getText();
double score = Double.parseDouble(tfScore.getText());
Student student = new Student(name, gender, age, major, score);
if (studentList.modify(name, student)) {
taOutput.setText("修改成功!\n" + studentList.toString());
clearInput();
} else {
taOutput.setText("修改失败!\n");
}
}
});
btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clearInput();
}
});
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = tfName.getText();
Student student = studentList.search(name);
if (student != null) {
taOutput.setText("查询成功!\n" + student.toString());
clearInput();
} else {
taOutput.setText("查询失败!\n");
}
}
});
btnSort.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
studentList.sort();
taOutput.setText("排序成功!\n" + studentList.toString());
clearInput();
}
});
}
private void clearInput() {
tfName.setText("");
rbMale.setSelected(true);
tfAge.setText("");
tfMajor.setText("");
tfScore.setText("");
}
public static void main(String[] args) {
new ScoreManagementSystem();
}
}
class Student {
private String name;
private String gender;
private int age;
private String major;
private double score;
public Student(String name, String gender, int age, String major, double score) {
this.name = name;
this.gender = gender;
this.age = age;
this.major = major;
this.score = score;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getAge() {
return age;
}
public String getMajor() {
return major;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public String toString() {
return "姓名:" + name + ",性别:" + gender + ",年龄:" + age + ",专业:" + major + ",成绩:" + score;
}
}
class StudentList {
private Student[] students;
private int size;
public StudentList() {
students = new Student[30];
size = 0;
}
public boolean add(Student student) {
if (size >= 30) {
return false;
}
students[size++] = student;
return true;
}
public boolean delete(String name) {
for (int i = 0; i < size; i++) {
if (students[i].getName().equals(name)) {
for (int j = i; j < size - 1; j++) {
students[j] = students[j + 1];
}
students[--size] = null;
return true;
}
}
return false;
}
public boolean modify(String name, Student student) {
for (int i = 0; i < size; i++) {
if (students[i].getName().equals(name)) {
students[i] = student;
return true;
}
}
return false;
}
public Student search(String name) {
for (int i = 0; i < size; i++) {
if (students[i].getName().equals(name)) {
return students[i];
}
}
return null;
}
public void sort() {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
if (students[i].getScore() < students[j].getScore()) {
Student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
}
public String toString() {
String str = "";
for (int i = 0; i < size; i++) {
str += students[i].toString() + "\n";
}
return str;
}
}
```
以上代码实现了一个简单的班级成绩管理系统,包含了学生信息的添加、删除、修改、搜索、排序等功能。用户可以通过图形用户界面方便地操作系统。注意,这只是一个示例代码,仅供参考,具体实现还需要根据需求进行调整和修改。
阅读全文