⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a04dd498ee55001c1d4bf407d9c2270d

📁 这是一个用java编写的学生成绩管理系统
💻
字号:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;

public class GuanLi extends JFrame implements ActionListener {

	String xm;

	int i, j, xh, yy, gs, wl, zt;

	JLabel prompt1 = new JLabel("学生成绩管理系统");
	JLabel prompt2 = new JLabel("			用户:");
	JLabel prompt3 = new JLabel("			密码:");
	JLabel prompt4 = new JLabel("			姓名:");
	JLabel prompt5 = new JLabel("			学号:");
	JLabel prompt6 = new JLabel("			高等数学:");
	JLabel prompt7 = new JLabel("			大学英语:");
	JLabel prompt8 = new JLabel("			大学物理:");
	JLabel prompt9 = new JLabel("			机械制图:");

	JTextField input1 = new JTextField(8);
	JTextField input2 = new JTextField(8);
	JTextField input3 = new JTextField(8);
	JTextField input4 = new JTextField(8);
	JTextField input5 = new JTextField(8);
	JTextField input6 = new JTextField(8);
	JTextField input7 = new JTextField(8);
	JTextField input8 = new JTextField(8);
	JButton btn1 = new JButton("登录");
	JButton btn2 = new JButton("增加记录");
	JButton btn3 = new JButton("修改记录");
	JButton btn4 = new JButton("删除记录");
	JButton btn5 = new JButton("学生查询");

	public GuanLi() {

		getContentPane().setLayout(new GridLayout(10, 2));

		getContentPane().add(new JLabel());
		getContentPane().add(prompt1);

		getContentPane().add(new JLabel());
		getContentPane().add(prompt2);
		getContentPane().add(input1);

		getContentPane().add(new JLabel());
		getContentPane().add(prompt3);
		getContentPane().add(input2);
		getContentPane().add(btn1);

		getContentPane().add(prompt4);
		getContentPane().add(input3);

		getContentPane().add(new JLabel());
		getContentPane().add(prompt5);
		getContentPane().add(input4);

		getContentPane().add(new JLabel());
		getContentPane().add(prompt6);
		getContentPane().add(input5);

		getContentPane().add(new JLabel());
		getContentPane().add(prompt7);
		getContentPane().add(input6);

		getContentPane().add(new JLabel());
		getContentPane().add(prompt8);
		getContentPane().add(input7);
		getContentPane().add(new JLabel());
		getContentPane().add(prompt9);
		getContentPane().add(input8);
		getContentPane().add(btn5);
		getContentPane().add(btn2);
		getContentPane().add(btn3);
		getContentPane().add(btn4);

		prompt6.setVisible(false);
		prompt7.setVisible(false);
		prompt8.setVisible(false);
		prompt9.setVisible(false);
		input5.setVisible(false);
		input6.setVisible(false);
		input7.setVisible(false);
		input8.setVisible(false);
		btn2.setVisible(false);
		btn3.setVisible(false);
		btn4.setVisible(false);
		btn1.addActionListener(this);
		btn2.addActionListener(this);
		btn3.addActionListener(this);
		btn4.addActionListener(this);
		btn5.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand() == "登录") {
			String a, b;
			a = input1.getText();
			b = input2.getText();
			input1.setText("");
			if ((a.equals("zhaoweihua") == true)
					&& (b.equals("123456") == true)) {
				try {
					Connection con = DBConnection.getConncetion();
					con.close();
				} catch (SQLException ex) {
					System.out.println(ex.toString());
					System.out.println("Error!!");
				} catch (java.lang.Exception ex) {
					ex.printStackTrace();
				}

				prompt4.setVisible(true);
				prompt5.setVisible(true);
				prompt6.setVisible(true);
				prompt7.setVisible(true);
				btn5.setLabel("用户查询");

				prompt8.setVisible(true);
				prompt9.setVisible(true);
				input3.setVisible(true);
				input4.setVisible(true);
				input5.setVisible(true);
				input6.setVisible(true);
				input7.setVisible(true);
				input8.setVisible(true);
				btn2.setVisible(true);
				btn3.setVisible(true);
				btn4.setVisible(true);

				btn1.setVisible(false);
				input1.setText("登录成功");
				input2.setText("");
				input1.selectAll();
			} else
				input2.setText("用户名或密码错");
		}
		if (e.getActionCommand() == "增加记录") {
			boolean scucss = true;
			try {
				xm = input3.getText();
				xh = Integer.parseInt(input4.getText());

				yy = Integer.parseInt(input6.getText());
				gs = Integer.parseInt(input5.getText());
				wl = Integer.parseInt(input7.getText());
				zt = Integer.parseInt(input8.getText());
				Connection con = DBConnection.getConncetion();
				Statement stmt = con.createStatement();
				stmt.executeUpdate("INSERT INTO chengjiguanli VALUES('" + xm+ "'," + xh + "," + gs + "," + yy + "," + wl + "," + zt+ ")");
				 con.commit();
				stmt.close();
				con.close();
				input1.setText("增加成功");
				input2.setText("");
				input3.setText("");
				input4.setText("");
				input5.setText("");
				input6.setText("");
				input7.setText("");
				input8.setText("");
				
			} catch (SQLException ex) {
				System.out.println(ex.toString());
				System.out.println("Error!!");
			} catch (java.lang.Exception ex) {
				ex.printStackTrace();
			}

			try {
				XingMing();
			} catch (EmptyException as) {
				input3.setText("姓名不能为空");
				scucss = false;
			}
			try {
				xh = Integer.parseInt(input4.getText());
			} catch (NumberFormatException m) {
				input4.setText("学号为空或格式错");
				scucss = false;
			}

			try {
				YY();
			} catch (EmptyException as) {
				yy = -1;
			} catch (OverException dd) {
				input6.setText("应在0-100间");
				scucss = false;
			} catch (NumberFormatException cm) {
				input6.setText("成绩应为数据");
				scucss = false;
			}
			try {
				GS();
			} catch (EmptyException as) {
				gs = -1;
			} catch (OverException dd) {
				input5.setText("应在0-100间");
				scucss = false;
			} catch (NumberFormatException cm) {
				input5.setText("成绩应为数据");
				scucss = false;
			}
			try {
				WL();
			} catch (EmptyException as) {
				wl = -1;
			} catch (OverException dd) {
				input7.setText("应在0-100间");
				scucss = false;
			} catch (NumberFormatException cm) {
				input7.setText("成绩应为数据");
				scucss = false;
			}
			try {
				ZT();
			} catch (EmptyException as) {
				zt = -1;
			} catch (OverException dd) {
				input8.setText("应在0-100间");
				scucss = false;
			} catch (NumberFormatException cm) {
				input8.setText("成绩应为数据");
				scucss = false;
			}
			if (scucss == true) {

			}
		}
		if (e.getActionCommand() == "修改记录")

		{
			try {
				xm = input3.getText();
				xh = Integer.parseInt(input4.getText());

				yy = Integer.parseInt(input6.getText());
				gs = Integer.parseInt(input5.getText());
				wl = Integer.parseInt(input7.getText());
				zt = Integer.parseInt(input8.getText());
				Connection con = DBConnection.getConncetion();
				Statement stmt = con.createStatement();
				stmt.executeUpdate("UPDATE chengjiguanli SET Math=" + gs+ ",English=" + yy + ",Physical=" + wl + ",Draw=" + zt+ " WHERE Sname='" + xm + "' AND Sno=" + xh + "");
				 con.commit();
				stmt.close();
				con.close();
				input1.setText("修改成功");
				input2.setText("");
				input3.setText("");
				input4.setText("");
				input5.setText("");
				input6.setText("");
				input7.setText("");
				input8.setText("");
			}

			catch (SQLException ex) {
				System.out.println(ex.toString());
				System.out.println("Error!!");
			} catch (java.lang.Exception ex) {
				ex.printStackTrace();
			}

		}
		if (e.getActionCommand() == "删除记录") {
			try {
				xm = input3.getText();
				xh = Integer.parseInt(input4.getText());
				Connection con = DBConnection.getConncetion();
				Statement stmt = con.createStatement();
				stmt.executeUpdate("DELETE FROM chengjiguanli WHERE Sname='"+xm+"'AND Sno=" + xh + "");
			 con.commit();
				stmt.close();
				con.close();

				input1.setText("删除成功");
				input2.setText("");
				input3.setText("");
				input4.setText("");
				input5.setText("");
				input6.setText("");
				input7.setText("");
				input8.setText("");
			} catch (SQLException ex) {
				System.out.println(ex.toString());
				System.out.println("Error!!");
			} catch (java.lang.Exception ex) {
				ex.printStackTrace();
			}
			// StuInf.removeElementAt(mid);

		}
		if (e.getActionCommand() == "用户查询") {
			boolean right = true;
			try {
				xh = Integer.parseInt(input4.getText());
			} catch (NumberFormatException m) {
				input4.setText("学号为空或格式错");
				right = false;
			}
			if (right == true) {
				try {

					xh = Integer.parseInt(input4.getText());
					Connection con = DBConnection.getConncetion();
					Statement stmt = con.createStatement();

					ResultSet rs = stmt
							.executeQuery("SELECT * FROM chengjiguanli WHERE Sno="+ xh + "");
					rs.next();
					String i = rs.getString(1);
					
					String j = rs.getString(3);
					String k = rs.getString(4);
					String m = rs.getString(5);
					String n = rs.getString(6);
					input3.setText(i);
					
					input5.setText(j);
					input6.setText(k);
					input7.setText(m);
					input8.setText(n);
					String a=rs.getString("Sno");
					con.close();
					stmt.close();
					rs.close();
				} catch (SQLException ex) {
					input4.setText("没有找到相关记录,请重新输入");
					System.out.println(ex.toString());
					System.out.println("Error!!");
				} 
				
			
				catch (java.lang.Exception ex) {
					ex.printStackTrace();
				}


				btn3.setEnabled(true);
				btn4.setEnabled(true);
			}
		}
		if (e.getActionCommand() == "学生查询") {
			boolean right = true;
			prompt2.setVisible(false);
			prompt3.setVisible(false);
			prompt6.setVisible(true);
			prompt7.setVisible(true);
			prompt8.setVisible(true);
			prompt9.setVisible(true);
			btn1.setVisible(false);
			btn2.setVisible(false);
			btn3.setVisible(false);
			btn4.setVisible(false);
			input1.setVisible(false);
			input2.setVisible(false);
			input5.setVisible(true);
			input6.setVisible(true);
			input7.setVisible(true);
			input8.setVisible(true);
			try {
				xh = Integer.parseInt(input4.getText());
			} catch (NumberFormatException m) {
				input4.setText("学号为空或格式错");
				right = false;
			}
			if (right == true) {
				try {
					xh = Integer.parseInt(input4.getText());
					Connection con = DBConnection.getConncetion();
					Statement stmt = con.createStatement();

					ResultSet rs = stmt.executeQuery("SELECT * FROM chengjiguanli WHERE Sno="+ xh + "");
                    rs.next();
					String i = rs.getString(1);
					
					String j = rs.getString(3);
					String k = rs.getString(4);
					String m = rs.getString(5);
					String n = rs.getString(6);
					input3.setText(i);
					
					input5.setText(j);
					input6.setText(k);
					input7.setText(m);
					input8.setText(n);
					String a=rs.getString("Sno");
					con.close();
					stmt.close();
					rs.close();
				} catch (SQLException ex) {
					input4.setText("没有找到相关记录,请重新输入");
					System.out.println(ex.toString());
					
					System.out.println("Error!!");
				} catch (java.lang.Exception ex) {
					ex.printStackTrace();
				}

				btn3.setEnabled(true);
				btn4.setEnabled(true);
			}
		}

	}

	// 异常类
	class OverException extends Exception {
		String over;
	}

	class EmptyException extends Exception {
		String empty;
	}

	void XingMing() throws EmptyException {
		if ((input3.getText()).equals(""))
			throw (new EmptyException());
		else
			xm = input3.getText();

	}

	void YY() throws OverException, EmptyException {
		if ((input6.getText()).equals(""))
			throw (new EmptyException());
		else
			yy = Integer.parseInt(input6.getText());
		if (yy < 0 || yy > 100)
			throw (new OverException());
	}

	void WL() throws OverException, EmptyException {
		if ((input7.getText()).equals(""))
			throw (new EmptyException());
		else
			wl = Integer.parseInt(input7.getText());
		if (wl < 0 || wl > 100)
			throw (new OverException());
	}

	void ZT() throws OverException, EmptyException {
		if ((input8.getText()).equals(""))
			throw (new EmptyException());
		else
			zt = Integer.parseInt(input8.getText());
		if (zt < 0 || zt > 100)
			throw (new OverException());
	}

	void GS() throws OverException, EmptyException {
		if ((input5.getText()).equals(""))
			throw (new EmptyException());
		else
			gs = Integer.parseInt(input5.getText());
		if (gs < 0 || gs > 100)
			throw (new OverException());
	}

	public static void main(String[] args) {
		GuanLi frame = new GuanLi();
		frame.setTitle("欢迎登录学生成绩管理系统");
		frame.setSize(800, 600);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -