项目简介:
项目名称:学生基本信息管理
团队成员:吴龙飞,游俊臻
团队成员以及负责模块:
| 姓名 | 任务分配 |
|---|---|
| 吴龙飞(组长) | 管理界面编写,文件读写 |
| 游俊臻 | gui界面设计,登录界面 |
功能要求:
1)需要管理的学生信息有:学号、姓名、性别、出生日期、政治面貌、家庭住址、电话、宿舍号。
2)实现查询、增、删、改等功能。
数据存储:文件。
项目git地址:
https://gitee.com/Aczas/java-code/tree/master/Student_system
项目功能结构图:
项目运行演示:
1.登录和注册界面
2.主界面
3.主要功能-添加/修改/删除/查找/展示学生信息
项目关键代码:
主菜单代码
package GUI;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import student.Date;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import java.awt.Font;
public class MainMenu extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainMenu frame = new MainMenu();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainMenu() {
setTitle("\u5B66\u751F\u57FA\u672C\u4FE1\u606F\u7BA1\u7406\u7CFB\u7EDF");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 535, 391);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("\u6DFB\u52A0\u5B66\u751F\u4FE1\u606F");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
new AddOperation().setVisible(true);
dispose();
}
});
btnNewButton.setBounds(26, 71, 200, 45);
contentPane.add(btnNewButton);
JButton btnNewButton_1 = new JButton("\u5220\u9664\u5B66\u751F\u4FE1\u606F");
btnNewButton_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
new DeleteOperation().setVisible(true);
dispose();
}
});
btnNewButton_1.setBounds(290, 164, 200, 45);
contentPane.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("\u67E5\u627E\u5B66\u751F\u4FE1\u606F");
btnNewButton_2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
new SearchOperation().setVisible(true);
dispose();
}
});
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnNewButton_2.setBounds(290, 71, 200, 45);
contentPane.add(btnNewButton_2);
JButton btnNewButton_3 = new JButton("\u663E\u793A\u6240\u6709\u4FE1\u606F");
btnNewButton_3.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
new DisplayOperation().setVisible(true);
dispose();
Date.display();
}
});
btnNewButton_3.setBounds(26, 261, 200, 45);
contentPane.add(btnNewButton_3);
JButton btnNewButton_4 = new JButton("\u4FDD\u5B58\u5E76\u9000\u51FA");
btnNewButton_4.setFont(new Font(" ", Font.PLAIN, 18));
btnNewButton_4.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Date.flush();
dispose();
}
});
btnNewButton_4.setBounds(290, 261, 200, 45);
contentPane.add(btnNewButton_4);
JButton btnNewButton_5 = new JButton("\u4FEE\u6539\u5B66\u751F\u4FE1\u606F");
btnNewButton_5.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
new ModifyOperation().setVisible(true);
dispose();
}
});
btnNewButton_5.setBounds(26, 164, 200, 45);
contentPane.add(btnNewButton_5);
JLabel lblNewLabel = new JLabel("\u5B66\u751F\u4FE1\u606F\u7BA1\u7406\u7CFB\u7EDF");
lblNewLabel.setBounds(160, 13, 232, 27);
contentPane.add(lblNewLabel);
}
}
数据操作代码
package student;
import java.awt.Component;
import java.util.ArrayList;
import io.input;
import io.output;
public class Date {
public static String file_user = "C:\\Users\\newid\\Desktop\\user.txt";
public static String file_students = "C:\\Users\\newid\\Desktop\\students.txt";
public static ArrayList<String> str_user = new ArrayList<String>();
public static ArrayList<String> str_students = new ArrayList<String>();
public static void menu() {
System.out.println("1-学生信息一览\r\n" + "2-增加学生信息\r\n" + "3-删除学生信息\r\n" + "4-查找用户信息\r\n" + "5-修改学生信息\r\n"
+ "6-保存并退出\r\n" + "\r\n" + "请输入:");
}
/* 装载数据 */
public static void info_loading() {
input.from(file_user);
input.from(file_students);
}
public static void flush() {
int flag = 1;
for (String e : str_students)
if (flag == 1) {
output.out_to(file_students, e + "\r\n", false);
flag = 0;
} else
output.out_to(file_students, e + "\r\n", true);
}
public static void display() {
for (String e : str_students)
System.out.println(e);
}
public static boolean add(String str) {
return Date.str_students.add(str);
}
public static boolean delete(String str) {
return str_students.remove(str);
}
/* 在指定文档里查找指定数据 */
public static String seek(String file, String str) {
if (file.equals(file_user))
for (String e : str_user) {
if (e.equals(str))
return e;
}
if (file.equals(file_students))
for (String e : str_students)
if (e.contains(str))
return e;
return null;
}
public static boolean modify(String str1, String str2) {
return (str_students.set(str_students.indexOf(str1), str2) != null);
}
}
总结:
通过此次课程设计,我认识到我们小组还有很大进步空间——完成的不是很好。。。主要问题出现在GUI界面的编写上面,比如在列表框中选中和删除数据、在点击确认按钮后弹出对话框来进行提示以及具体布局的合理性和美感、文本的设计和处理;这些都是在课程设计中未完成或完成的不够好的地方,还有就是没有实现使用数据库来持久化存储数据,这也是以后需要改进的地方;再有是在数据的处理方面,比如模糊匹配、模糊查找、自动生成所需要的数据类型,GUI数据图形化等。希望能在以后的学习里,不断完善自己的能力,做出更优秀的程序。