Java+Swing+mysql学生信息管理系统

Java+Swing+mysql学生信息管理系统

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

一、系统介绍

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

二、功能展示

1.管理员登陆

Java+Swing+mysql学生信息管理系统_第1张图片

2.学生信息查询

Java+Swing+mysql学生信息管理系统_第2张图片

3.学生信息添加

Java+Swing+mysql学生信息管理系统_第3张图片

4.学生信息修改

Java+Swing+mysql学生信息管理系统_第4张图片

5.删除

Java+Swing+mysql学生信息管理系统_第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 list=studentdao.queryStudent(sno);
        rowData=new Object[list.size()][columnNames.length];

        for(int i=0;i

四、其它

1.其他系统实现

Java+Swing实现学生选课管理系统
Java+Swing实现学校教务管理系统
Java+Swing+sqlserver学生成绩管理系统
Java+Swing用户信息管理系统
Java+Swing实现的五子棋游戏
基于JavaSwing 银行管理系统
Java+Swing+mysql仿QQ聊天工具
Java+Swing 聊天室
Java+Swing+dat文件存储实现学生选课管理系统
Java+Swing可视化图像处理软件
Java+Swing学生信息管理系统
Java+Swing图书管理系统
Java+Swing图书管理系统2.0
基于java+swing+mysql图书管理系统3.0
大作业-基于java+swing+mysql北方传统民居信息管理系统

2.获取源码

点击下载
JavaSwing+mysql学生信息管理系统

你可能感兴趣的:(JavaSwing项目,java,mysql,eclipse)