Java_GUI——学生管理系统

                                               用很笨的办法,实现了一个简单而且BUG巨多的系统~

//测试代码

package 学员管理系统GUI;

import javax.swing.JFrame;

public class StudentGUITest 
{
	
	public static void main(String[] args)
	{
		new GUI().Login();
	}
}

//登录界面

package 学员管理系统GUI;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

class GUI
{
	//登录界面
	public void Login()
	{
		//登录界面容器定义
		JFrame f =new JFrame("登录");
		JPanel p1 = new JPanel(new GridLayout(3,2,0,5));
		JPanel p2 = new JPanel(new FlowLayout());
		
		//登录界面组件设置
		
		JLabel j1 = new JLabel("                  学    号 :");
		JLabel j2 = new JLabel("                  密    码 :");
		JLabel j3 = new JLabel("                    ");
		JLabel j4 = new JLabel("                    ");
		JTextField jt1 = new JTextField();//两个输入
		JTextField jt2 = new JTextField();
		
		JButton b1 = new JButton("登录");
		JButton b2 = new JButton("取消");
		
		//容器添加
		p1.add(j1);
		p1.add(jt1);
		p1.add(j2);
		p1.add(jt2);
		p1.add(j4);
		
		p2.add(b1);
		p2.add(b2);
		
		f.add(j3,"North");
		f.add(p2,"South");
		f.add(p1);
		
		//组件设置
		jt1.setFont(new Font("宋体", 1, 30));
		jt2.setFont(new Font("宋体", 1, 30));
		
		
		
		//监听器绑定
			//1.登录按钮
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(jt1.getText().equals(""))				//判断用户名是否为空
					System.out.println("请输入用户名!");
				else
				{
					if(jt1.getText().equals("孙文")) 		//默认用户名
						if(jt2.getText().equals("123"))		//默认密码
						{
							new MainInterface();
							f.setVisible(false);
						}
						else
							new Tips();
					else
						new Tips();
				}
			}
		});
			//2.取消按钮
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		
		//容器设置
		f.setBounds(300, 300, 270, 200);
		f.setLocationRelativeTo(null);	//窗口居中
		f.setResizable(false);			//窗口大小不可调
		f.setVisible(true);
	}
}
//用户密码不正确提示界面
class Tips
{
	//用户密码不正确提示界面方法
	public Tips()
	{
		//登录界面容器定义
		JFrame f =new JFrame("提示");
		f.setLayout(new GridLayout(2,1,0,5));
		JPanel p1 = new JPanel(new FlowLayout());
		
		
		//登录界面组件设置
		JLabel j1 = new JLabel("   用户名或密码不正确!");
		JButton b1 = new JButton("确定");
		
		
		//组件设置
		j1.setFont(new Font("宋体", 1, 20));
		
		
		//监听器绑定
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				f.setVisible(false);
			}
		});
		//容器添加
		p1.add(b1);
		f.add(j1);
		f.add(p1);
		
		//容器设置
		f.setBounds(300, 300, 270, 170);
		f.setLocationRelativeTo(null);	//窗口居中
		f.setResizable(false);		//窗口大小不可调
		f.setVisible(true);
		
	}
}

//主界面

//代码复用巨多,为了自己下次能更快的理解,就没用循环

package 学员管理系统GUI;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JTextField;

//主界面
class MainInterface 
{
	public static JLabel[] j = new JLabel[70];				//添加的静态数组
	public static JLabel[] jj1 = new JLabel[7];			//查询的静态数组
	public static JTextField[] jj2 = new JTextField[7];	//修改的静态数组
	public static Student[] stu = new Student[10];
	public static int sum = 0;
	public MainInterface()
	{
		
		for(int i = 0 ;i < stu.length;i++)
			stu[i] = new Student();
		
		
		//容器创建
		JFrame f = new JFrame("学员管理系统");
		JPanel p1 = new JPanel(new GridLayout(11,7,0,10));	//中部
		JPanel p2 = new JPanel(new GridLayout(1,7,0,0));	//上部
		JPanel p3 = new JPanel();							//下部
		
		//创建组件 
		JLabel j1 = new JLabel("                                  学号:");
		JLabel j2 = new JLabel("     ");					//上部的左右空栏
		JLabel j3 = new JLabel("     ");
		JLabel j4 = new JLabel("     ");
		JLabel j5 = new JLabel("     ");
		
		JTextField jt1 = new JTextField();					//查询输入栏
	
		JButton b1 = new JButton("查询");
		JButton b2 = new JButton("添加");
		JButton b3 = new JButton("删除");
		JButton b4 = new JButton("修改");
		JButton b5 = new JButton("退出");
			//表头
		JButton b11 = new JButton("学号");
		JButton b12 = new JButton("姓名");
		JButton b13 = new JButton("性别");
		JButton b14 = new JButton("年龄");
		JButton b15 = new JButton("手机号");
		JButton b16 = new JButton("QQ");
		JButton b17 = new JButton("E-mail");
		
	
	
		//组件设置
		jt1.setFont(new Font("宋体", 1, 15));
		for(int i = 0;i < 70; i++)
			j[i] = new JLabel();
		for(int i = 0; i < 70 ; i++ )
			j[i].setHorizontalAlignment(JTextField.CENTER);	//居中对齐

		
		//组件添加
		p1.add(b11);
		p1.add(b12);
		p1.add(b13);
		p1.add(b14);
		p1.add(b15);
		p1.add(b16);
		p1.add(b17);
		for(int i = 0; i < 70; i++)
			p1.add(j[i]);
		
		
		p2.add(j2);
		p2.add(j3);
		p2.add(j1);
		p2.add(jt1);
		p2.add(b1);
		p2.add(j4);
		p2.add(j5);
		
		
		p3.add(b2);
		p3.add(b3);
		p3.add(b4);
		p3.add(b5);
		
		
		f.add(p1);
		f.add(p2,"North");
		f.add(p3,"South");
		
		
		//监听器的绑定
			//1 查询
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for(int i = 0;i < 7; i++)
					jj1[i] = new JLabel();
				for(int i = 0; i < Student.STUDENTSUM ;i++)
				{
					if(jt1.getText().equals(stu[i].getNum())) 
					{
						jj1[0].setText(stu[i].getNum());
						jj1[1].setText(stu[i].getName());
						jj1[2].setText(stu[i].getGender());
						jj1[3].setText(stu[i].getAge());
						jj1[4].setText(stu[i].getNumber());
						jj1[5].setText(stu[i].getQq());
						jj1[6].setText(stu[i].getEmail());
						break;
					}
				}
				
				new Menu1().Query();	
			}
		});
			//2 添加
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new Menu1().Add();
			}
		});
			//3 删除
		b3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new Menu1().Del();
			}
		});

		//4 修改
		b4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new Menu1().Modify();
			}
		});
			//5 退出
		b5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		
		
		//容器设置
		f.setBounds(0,0, 1000, 800);
		f.setLocationRelativeTo(null);	//窗口居中
		f.setResizable(false);			//窗口大小不可调
		f.setVisible(true);
	}
}

//次级界面总汇
class Menu1
{
	//次级界面1 添加界面
	public void Add()
	{
		//容器创建
		JFrame f = new JFrame("学员管理系统");
		JPanel p = new JPanel(new GridLayout(7,2,0,10))	; //中部
		JPanel p1 = new JPanel();//下部
		
		//组件建立
		JLabel j1 = new JLabel("            学  号 :");
		JLabel j2 = new JLabel("            姓  名 :");
		JLabel j3 = new JLabel("            性  别 :");
		JLabel j4 = new JLabel("            年  龄 :");
		JLabel j5 = new JLabel("            手  机 :");
		JLabel j6 = new JLabel("            Q   Q :");
		JLabel j7 = new JLabel("            E-mail :");
		
		JTextField jt1 = new JTextField();		//七个输入
		JTextField jt2 = new JTextField();
		JTextField jt3 = new JTextField();
		JTextField jt4 = new JTextField();
		JTextField jt5 = new JTextField();
		JTextField jt6 = new JTextField();
		JTextField jt7 = new JTextField();
		
		JButton b1 = new JButton("添加");
		JButton b2 = new JButton("取消");
		
		//jt1.setHorizontalAlignment(JTextField.CENTER); 居中
		
		//组件添加
		p.add(j1);
		p.add(jt1);
		p.add(j2);
		p.add(jt2);
		p.add(j3);
		p.add(jt3);
		p.add(j4);
		p.add(jt4);
		p.add(j5);
		p.add(jt5);
		p.add(j6);
		p.add(jt6);
		p.add(j7);
		p.add(jt7);
		
		p1.add(b1);
		p1.add(b2);
		
		f.add(p);
		f.add(p1,"South");
		
		//监听器绑定
			//1、取消
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				f.setVisible(false);
			}
		});
			//2、添加
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(MainInterface.sum < 70)				//最多70个人
				{	
					MainInterface.stu[Student.STUDENTSUM].setNum(jt1.getText());	//得到七个输入
					MainInterface.stu[Student.STUDENTSUM].setName(jt2.getText());
					MainInterface.stu[Student.STUDENTSUM].setGender(jt3.getText());
					MainInterface.stu[Student.STUDENTSUM].setAge(jt4.getText());
					MainInterface.stu[Student.STUDENTSUM].setNumber(jt5.getText());
					MainInterface.stu[Student.STUDENTSUM].setQq(jt6.getText());
					MainInterface.stu[Student.STUDENTSUM].setEmail(jt7.getText());
					
					//赋值
					MainInterface.j[MainInterface.sum+0].setText(MainInterface.stu[Student.STUDENTSUM].getNum());
					MainInterface.j[MainInterface.sum+1].setText(MainInterface.stu[Student.STUDENTSUM].getName());
					MainInterface.j[MainInterface.sum+2].setText(MainInterface.stu[Student.STUDENTSUM].getGender());
					MainInterface.j[MainInterface.sum+3].setText(MainInterface.stu[Student.STUDENTSUM].getAge());
					MainInterface.j[MainInterface.sum+4].setText(MainInterface.stu[Student.STUDENTSUM].getNumber());
					MainInterface.j[MainInterface.sum+5].setText(MainInterface.stu[Student.STUDENTSUM].getQq());
					MainInterface.j[MainInterface.sum+6].setText(MainInterface.stu[Student.STUDENTSUM].getEmail());
				
					MainInterface.sum+=7;
					Student.STUDENTSUM++;
				}
			}
		});
		
		//容器设置
		f.setBounds(0,0, 250, 300);
		f.setLocationRelativeTo(null);	//窗口居中
		f.setResizable(false);			//窗口大小不可调
		f.setVisible(true);
	}
	
	//次级界面2 删除界面
	public void Del()
	{
		//容器创建
		JFrame f = new JFrame("删除界面");
		JPanel p = new JPanel();
		f.setLayout(new GridLayout(3,1,0,10));
		
		//组件创建
		JTextField jt1 = new JTextField();
		JLabel j2 = new JLabel("请输入删除学号:");

		JButton b1 = new JButton("删除");
		JButton b2 = new JButton("取消");
		
		//组件设置
		j2.setHorizontalAlignment(JTextField.CENTER);//右对齐
		jt1.setFont(new Font("宋体",1,30));
		
		//组件添加
		f.add(j2);
		f.add(jt1);
		p.add(b1);
		p.add(b2);
		f.add(p);
		

		//监听器绑定
			//1、取消按钮
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				f.setVisible(false);
			}
		});
			//2、删除按钮
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for(int i = 0; i < Student.STUDENTSUM ;i++)
				{
					if(jt1.getText().equals(MainInterface.stu[i].getNum())) 
					{
						MainInterface.j[i*7+0].setText("");
						MainInterface.j[i*7+1].setText("");
						MainInterface.j[i*7+2].setText("");
						MainInterface.j[i*7+3].setText("");
						MainInterface.j[i*7+4].setText("");
						MainInterface.j[i*7+5].setText("");
						MainInterface.j[i*7+6].setText("");
						i=0;
						break;
					}
				}
				f.setVisible(false);
			}
		});
		
		
		//容器设置
		f.setBounds(0,0, 350, 200);
		f.setLocationRelativeTo(null);	//窗口居中
		f.setResizable(false);			//窗口大小不可调
		f.setVisible(true);
	}
	//次级界面3 查询界面
	public void Query()
	{
		//容器创建
		JFrame f = new JFrame("查询显示界面");
		JPanel p = new JPanel(new GridLayout(7,2,0,10))	; //中部
		JPanel p1 = new JPanel();//下部
		
		//组件建立
		JLabel j1 = new JLabel("            学  号 :");
		JLabel j2 = new JLabel("            姓  名 :");
		JLabel j3 = new JLabel("            性  别 :");
		JLabel j4 = new JLabel("            年  龄 :");
		JLabel j5 = new JLabel("            手  机 :");
		JLabel j6 = new JLabel("            Q   Q :");
		JLabel j7 = new JLabel("            E-mail :");
		
		
		
		JButton b1 = new JButton("确定");

		
		//jt1.setHorizontalAlignment(JTextField.CENTER); 居中
		
		//组件添加
		p.add(j1);
		p.add(MainInterface.jj1[0]);
		p.add(j2);
		p.add(MainInterface.jj1[1]);
		p.add(j3);
		p.add(MainInterface.jj1[2]);
		p.add(j4);
		p.add(MainInterface.jj1[3]);
		p.add(j5);
		p.add(MainInterface.jj1[4]);
		p.add(j6);
		p.add(MainInterface.jj1[5]);
		p.add(j7);
		p.add(MainInterface.jj1[6]);
		
		p1.add(b1);
		
		f.add(p);
		f.add(p1,"South");
		
		//监听器绑定
			//1、确定按钮
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
				f.setVisible(false);
			}
		});
		
		//容器设置
		f.setBounds(0,0, 300, 300);
		f.setLocationRelativeTo(null);	//窗口居中
		f.setResizable(false);			//窗口大小不可调
		f.setVisible(true);
		
	}
	
	//次级界面4 修改主界面
	public void Modify()
	{
		
		//容器创建
		JFrame f = new JFrame("修改界面");
		JPanel p = new JPanel();
		f.setLayout(new GridLayout(3,1,0,10));
		
		//组件创建
		JTextField jt1 = new JTextField();
		JLabel j2 = new JLabel("指定学生的学号进行修改:");

		JButton b1 = new JButton("进行修改");
		JButton b2 = new JButton("取消");
		
		//组件设置
		j2.setHorizontalAlignment(JTextField.CENTER);//右对齐
		jt1.setFont(new Font("宋体",1,30));
		
		//组件添加
		f.add(j2);
		f.add(jt1);
		p.add(b1);
		p.add(b2);
		f.add(p);
		

		//监听器绑定
			//1、取消按钮
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				f.setVisible(false);
			}
		});
			//2、进行修改按钮
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for(int i = 0 ;i < 7 ;i++)
					MainInterface.jj2[i] = new JTextField();
				
				for(int i = 0; i < Student.STUDENTSUM;i++)
				{
					if(jt1.getText().equals(MainInterface.stu[i].getNum()))
					{
						MainInterface.jj2[0].setText(MainInterface.stu[i].getNum());
						MainInterface.jj2[1].setText(MainInterface.stu[i].getName());
						MainInterface.jj2[2].setText(MainInterface.stu[i].getGender());
						MainInterface.jj2[3].setText(MainInterface.stu[i].getAge());
						MainInterface.jj2[4].setText(MainInterface.stu[i].getNumber());
						MainInterface.jj2[5].setText(MainInterface.stu[i].getQq());
						MainInterface.jj2[6].setText(MainInterface.stu[i].getEmail());
						break;
					}
					
				}
				
				Menu1.Modify_1();
				f.setVisible(false);
			}
		});
		
		
		//容器设置
		f.setBounds(0,0, 350, 200);
		f.setLocationRelativeTo(null);	//窗口居中
		f.setResizable(false);			//窗口大小不可调
		f.setVisible(true);
		
				
	}
	
	//次级界面4-1 修改子界面
	public static void Modify_1()
	{
		//容器创建
		JFrame f = new JFrame("修改子界面");
		JPanel p = new JPanel(new GridLayout(7,2,0,10))	; //中部
		JPanel p1 = new JPanel();						//下部
		
		//组件建立
		JLabel j1 = new JLabel("            学  号 :");
		JLabel j2 = new JLabel("            姓  名 :");
		JLabel j3 = new JLabel("            性  别 :");
		JLabel j4 = new JLabel("            年  龄 :");
		JLabel j5 = new JLabel("            手  机 :");
		JLabel j6 = new JLabel("            Q   Q :");
		JLabel j7 = new JLabel("            E-mail :");
		
		
		JButton b1 = new JButton("修改");
		JButton b2 = new JButton("取消");
		
		//jt1.setHorizontalAlignment(JTextField.CENTER); 居中
		
		//组件添加
		p.add(j1);
		p.add(MainInterface.jj2[0]);
		p.add(j2);
		p.add(MainInterface.jj2[1]);
		p.add(j3);
		p.add(MainInterface.jj2[2]);
		p.add(j4);
		p.add(MainInterface.jj2[3]);
		p.add(j5);
		p.add(MainInterface.jj2[4]);
		p.add(j6);
		p.add(MainInterface.jj2[5]);
		p.add(j7);
		p.add(MainInterface.jj2[6]);
		
		p1.add(b1);
		p1.add(b2);
		
		f.add(p);
		f.add(p1,"South");
		
		//监听器绑定
		//1、取消按钮
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				f.setVisible(false);
			}
		});
			//2、修改按钮
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for(int i = 0 ;i < Student.STUDENTSUM ; i++)
				{
					if(MainInterface.jj2[0].getText().equals(MainInterface.stu[i].getNum()))
					{
						MainInterface.j[i*7+0].setText(MainInterface.jj2[0].getText());
						MainInterface.j[i*7+1].setText(MainInterface.jj2[1].getText());
						MainInterface.j[i*7+2].setText(MainInterface.jj2[2].getText());
						MainInterface.j[i*7+3].setText(MainInterface.jj2[3].getText());
						MainInterface.j[i*7+4].setText(MainInterface.jj2[4].getText());
						MainInterface.j[i*7+5].setText(MainInterface.jj2[5].getText());
						MainInterface.j[i*7+6].setText(MainInterface.jj2[6].getText());
						break;
					}
					
				}
			}
		});
		
		//容器设置
		f.setBounds(0,0, 250, 300);
		f.setLocationRelativeTo(null);	//窗口居中
		f.setResizable(false);			//窗口大小不可调
		f.setVisible(true);
			
		
	}
}

 

  • 16
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
好的,我可以为您介绍如何使用 Python 制作一个简易的学生信息管理系统。这个系统将使用面向对象编程的方式实现,可以方便地添加、删除和修改学生信息。 首先,我们需要定义一个 `Student` 类,用来表示学生信息。每个学生都有姓名、学号、年龄等基本信息,可以使用类的属性来表示: ```python class Student: def __init__(self, name, student_id, age): self.name = name self.student_id = student_id self.age = age ``` 在 `__init__` 方法中,我们定义了三个属性,分别对应学生的姓名、学号和年龄。接下来,我们需要添加一些方法,来实现学生信息的添加、删除和修改: ```python class Student: def __init__(self, name, student_id, age): self.name = name self.student_id = student_id self.age = age def get_name(self): return self.name def set_name(self, name): self.name = name def get_student_id(self): return self.student_id def set_student_id(self, student_id): self.student_id = student_id def get_age(self): return self.age def set_age(self, age): self.age = age ``` 在上面的代码中,我们定义了六个方法,分别对应获取和设置学生的姓名、学号和年龄。这些方法可以方便地对学生信息进行修改。 接下来,我们可以创建一个 `StudentManager` 类,用来管理所有的学生信息。这个类包含了一个学生列表,可以添加、删除和修改学生信息: ```python class StudentManager: def __init__(self): self.students = [] def add_student(self, student): self.students.append(student) def remove_student(self, student): self.students.remove(student) def get_all_students(self): return self.students def search_student_by_id(self, student_id): for student in self.students: if student.get_student_id() == student_id: return student return None ``` 在上面的代码中,我们定义了四个方法,分别对应添加、删除、获取所有学生和根据学号查找学生。这些方法可以方便地对学生信息进行管理。 现在,我们可以创建一个 `main` 函数,来实现学生信息管理系统的基本功能: ```python def main(): manager = StudentManager() # 添加学生 student1 = Student('张三', '001', 18) manager.add_student(student1) student2 = Student('李四', '002', 19) manager.add_student(student2) student3 = Student('王五', '003', 20) manager.add_student(student3) # 查找学生 s = manager.search_student_by_id('001') print(s.get_name(), s.get_student_id(), s.get_age()) # 修改学生信息 s.set_name('赵六') s.set_age(21) # 删除学生 manager.remove_student(student3) # 打印所有学生信息 students = manager.get_all_students() for student in students: print(student.get_name(), student.get_student_id(), student.get_age()) ``` 在上面的代码中,我们首先创建了一个 `StudentManager` 对象,并添加了三个学生。然后,我们使用 `search_student_by_id` 方法查找学号为 '001' 的学生,并打印出其姓名、学号和年龄。接着,我们使用 `set_name` 和 `set_age` 方法修改了该学生的姓名和年龄。然后,我们使用 `remove_student` 方法删除了一个学生。最后,我们使用 `get_all_students` 方法获取所有学生信息,并打印出来。 这样,一个简易的学生信息管理系统就完成了。您可以根据自己的需求,继续添加其他功能,如文件读写、GUI 界面等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值