java学生信息管理系统+GUI界面布局+mysql数据库

代码已经更新!,重新设计了UI界面,代码之间的逻辑更加清晰

新的代码不需要手动建立数据库和表,全部由程序自动执行

用户名和密码为你数据库的用户名和密码!

评论区的方法已经不需要了

重复一遍!!!!

代码已经更新!不需要在自己手动建立数据库和表了!!!

可以先看教学视频再决定是否下载!

有需要的可以自行下载:
下载链接:
https://download.csdn/download/qq_52889967/15138909

教学视频:
https://v.qq/x/page/i3258e3o1pg.html

C语言写的在这里:
点击查看

python写的在这里:
点击查看

java实现聊天室:
https://blog.csdn/qq_52889967/article/details/118553306

java学生成绩管理系统:
https://blog.csdn/qq_52889967/article/details/118581246

先上图:

用户名和密码为自己的数据库的用户名和密码!!!




数据库信息:

本人使用的是MySQL5.7版本的数据库
数据库端口号为:3306
数据库连接名是:root
数据库用户名是:root
数据库名称是:mydatabase
建立的表是:student

部分源码展示如下:


//	定义容器
	public static JFrame jframe_1 =new JFrame("学生信息管理系统");
	public static JFrame jframe_2=new JFrame("登录");
//	定义面板
	public static JPanel jpanel_1=new JPanel(new FlowLayout());//流式布局
	public static JPanel jpanel_2=new JPanel(null);//空布局
//	设置文本区用于显示信息
	public static JTextArea j_1=new JTextArea();
//	登录界面的文本框和密码框
	JTextField jtext=new JTextField(12);
	JPasswordField jpassword=new JPasswordField(12);
//	学生信息的总数量(性别由单选按钮确定,所以是5个)
	public static int number=5;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		实例化对象
		System_UI UI=new System_UI();
		UI.init();
	}

//  登录界面
	public void init() {
		
//		窗口大小
		jframe_2.setSize(230,160);
//		流式布局
		jframe_2.setLayout(new FlowLayout());
//		窗口不可调整
		jframe_2.setResizable(false);
//		关闭窗口则退出程序
		jframe_2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
//		标签
		JLabel jlabel_1=new JLabel("用户名:");
		JLabel jlabel_2=new JLabel("密  码:");
//		设置密码框显示为*
		jpassword.setEchoChar('*');
//		字体
		Font font=new Font("宋体",Font.BOLD,18);
		jlabel_1.setFont(font);
		jlabel_2.setFont(font);
		//定义按钮
		JButton jbutton_1=new JButton("登录");
		JButton jbutton_2=new JButton("清除");
		jbutton_1.setFont(font);
		jbutton_2.setFont(font);
//		加入容器
		jframe_2.add(jlabel_1);
		jframe_2.add(jtext);
		jframe_2.add(jlabel_2);
		jframe_2.add(jpassword);
		jframe_2.add(jbutton_1);
		jframe_2.add(jbutton_2);
		
//		注册监听
		jbutton_1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
//				点击了登录按钮
//				将用户名和密码复制给MysqlOperation下的user和password
				MysqlOperation.user=jtext.getText();
//				jpassword.getPassword()获得的数据为char类型,需要转换为String
				String password=new String(jpassword.getPassword());
				MysqlOperation.password=password;
//				判断用户名和密码是否正确
//				如果用户名或密码错误,则会在MysqlOperation中的getConnection()方法下出现异常
				if(MysqlOperation.getConnection()!=null) {
					JOptionPane.showMessageDialog(
	                        jbutton_1,
	                        "登录成功!\n欢迎使用学生信息管理系统!",
	                        "提示",
	                        JOptionPane.INFORMATION_MESSAGE
	                );
//					隐藏登录界面
					System_UI.jframe_2.dispose();
//					初始化
					System_UI.init_1();
				}
			}
		});
//		添加学生的数据库方法
		public static void addStudent(JButton jbutton_1,JRadioButton radioBtn01,
				JTextField jtextfield[]) {
			Connection con=null;
			Statement stat=null;
			String sql=null;
			try {
//				建立数据库连接
				con=MysqlOperation.getConnection();
				stat=(Statement)con.createStatement();
//				性别为男
				if(radioBtn01.isSelected()) {
					sql="insert into student values('"+jtextfield[0].getText()+"','"
							+ ""+jtextfield[1].getText()+"','"+"男"+"','"+jtextfield[2].getText()
							+"','"+jtextfield[3].getText()+"','"+jtextfield[4].getText()+"')";
				}else {
					sql="insert into student values('"+jtextfield[0].getText()+"','"
							+jtextfield[1].getText()+"','"+"女"+"','"+jtextfield[2].getText()
							+"','"+jtextfield[3].getText()+"','"+jtextfield[4].getText()+"')";
				}
//				执行语句
				stat.executeUpdate(sql);
//				提示成功
				JOptionPane.showMessageDialog(
                        jbutton_1,
                        "添加学生信息成功!",
                        "提示",
                        JOptionPane.INFORMATION_MESSAGE
                );
			} catch (SQLException e) {
				// TODO Auto-generated catch block
//				处理异常情况,如学号重复,不打印异常
//				e.printStackTrace();
				JOptionPane.showMessageDialog(
                        jbutton_1,
                        "学号可能重复!\n添加学生信息失败!",
                        "警告",
                        JOptionPane.WARNING_MESSAGE
                );
			}finally {
				try {
					if(stat!=null)
						stat.close();
					if(con!=null)
						con.close();
				}catch(SQLException e) {
					e.printStackTrace();
				}
			}
			
		}
		

更多推荐

java学生信息管理系统(GUI+mysql数据库)