当前位置: 首页 > article >正文

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图书管理系统


http://www.kler.cn/a/381338.html

相关文章:

  • (附项目源码)python开发语言,基于python Web的高校毕业论文管理系统 51,计算机毕设程序开发+文案(LW+PPT)
  • RT-Thread操作系统(2)
  • Template Method(模板方法)
  • 【ACM出版,EI稳定检索,九大高校联合举办, IEEE Fellow支持】2024年计算机视觉与艺术研讨会(CVA 2024,11月29-12月1日)
  • gulp入门教程14:vinyl
  • 基于Matlab 模拟停车位管理系统【源码 GUI】
  • JZ8二叉树的下一个结点
  • P10 Pytorch入门实战——Pytorch实现车牌识别
  • WPF 特性------Binding
  • PySpark任务提交
  • Pr 沉浸式视频 - 自动 VR 属性
  • 查找重复的电子邮箱
  • Java 实现接口幂等的九种方法:确保系统稳定性与数据一致性
  • C语言字符数组 java封装
  • sql中判断一个字段是否包含一个数据的方法有哪些?
  • Spring Boot框架在教育领域的创新应用:导师双选系统
  • golang 实现比特币内核:处理椭圆曲线中的天文数字
  • uniapp在js方法中,获取当前用户的uid(uni-id-user)表中的用户id
  • OCR与PaddleOCR介绍
  • 服务器配置一个固定的IP然后可以通过ssh登录作为管理接口
  • 瑞派宠物医院轮值总裁胡文强受邀出席第三届宠物产业大会
  • 【MySQL】深层理解索引及特性(重点)--下(12)
  • Linux下的socket编程
  • LeetCode算法(二叉树)
  • vueui vxe-form 分享实现表单项的联动禁用,配置式表单方式的用法
  • 论文概览 |《IJGIS》2024.09 Vol.38 issue9