Java项目开发:学生社团管理系统

Java项目开发:学生社团管理系统

@author:Mr.Gu
@date:2021/5/31



项目需求

要求制作一个社团管理系统,要求链接数据库,实现普通用户注册社团,正确登录社团,实现用户可以浏览社团信息,创建社团,且只能创建一个社团,可以申请加入社团,团长
可以进入社团管理系统,对社团进行管理,发布活动等等。

开发环境

eclipse2018版
mysql5.7
jdk1.8
windowsbuilder

项目效果

在这里插入图片描述


在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。

二、项目源码

1.创建登录Jframe


public class LogFrm extends JFrame implements ActionListener {
	boolean flag;
	private JPanel contentPane;
	private JTextField nametf;
	private JPasswordField passwordField;
	User user = new User();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LogFrm frame = new LogFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LogFrm() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 596, 771);

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu menu = new JMenu("编辑注册");
		menuBar.add(menu);

		JMenuItem menuItem = new JMenuItem("注册账号");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Regist1 r = new Regist1();
				r.setVisible(true);

			}
		});
		menu.add(menuItem);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel lblNewLabel = new JLabel("社团管理系统");
		lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 37));
		lblNewLabel.setBounds(162, 154, 368, 122);
		contentPane.add(lblNewLabel);

		nametf = new JTextField();
		nametf.setBounds(162, 331, 223, 27);
		contentPane.add(nametf);
		nametf.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel(" 学号 :");
		lblNewLabel_1.setBounds(40, 334, 81, 21);
		contentPane.add(lblNewLabel_1);

		JLabel lblNewLabel_2 = new JLabel("密码 :");
		lblNewLabel_2.setBounds(50, 411, 81, 21);
		contentPane.add(lblNewLabel_2);

		JButton button = new JButton("重置");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rest();
			}
		});
		button.setBounds(88, 539, 123, 29);
		contentPane.add(button);

		JButton btnNewButton = new JButton("登录");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					login();
				} catch (HeadlessException | SQLException e1) {
					e1.printStackTrace();
				}
			}
		});
		btnNewButton.setBounds(340, 539, 123, 29);
		contentPane.add(btnNewButton);

		passwordField = new JPasswordField();
		passwordField.setBounds(162, 408, 223, 27);
		contentPane.add(passwordField);
		this.setLocationRelativeTo(null);
	}

	protected void login() throws HeadlessException, SQLException {
		boolean xyz = false;
		Mysql1 mysql = new Mysql1();
		mysql.connectSQL();
		String nameText = nametf.getText();
		String pwdText = new String(passwordField.getText());
		User user = new User(nameText, pwdText);
		/**
		 * 用于数据库连接
		 */
		Connection connection = null;

		if (StringUtil.isEmpty(nameText)) {
			JOptionPane.showMessageDialog(null, "用户名为空");

		} else {
			if (StringUtil.isEmpty(pwdText)) {
				JOptionPane.showMessageDialog(null, "密码不能为空");
			} else {

				try {
					this.flag = mysql.loginMatch(nameText, pwdText);
				} catch (SQLException e2) {

					e2.printStackTrace();
				} catch (Exception e2) {

					e2.printStackTrace();
				} // 清空输入栏
				rest();
				// 如果用户名判断成功则关闭login窗口并打开Spider窗口,否则状态栏显示loadfail;
				if (flag) {
					this.dispose();
					setall(nametf.getText());
					MainFrm mainFrm = new MainFrm(setall(nameText));
					mainFrm.setVisible(true);
				} else {
					JOptionPane.showMessageDialog(null, "账号或密码错误");
				}
			}
		}
	}

	private User setall(String id) throws SQLException {
		String url = "jdbc:mysql://localhost:3306/student?useSSL=false";// url是固定的
		// jdbc:mysql://localhost:3036/数据库名
		String user3 = "root";// 这里一般是root
		String password = "root";// 这是登陆数据库的密码,我的密码为空

		String word3 = "select * from userinfo";
		ResultSet resultSet = null;

		boolean x = false;
		String anameString = new String();
		Connection con = (Connection) DriverManager.getConnection(url, user3, password);// 创建连接对象,来连接数据库
		PreparedStatement ps0 = con.prepareStatement(word3);// 创建执行对象
		resultSet = ps0.executeQuery(word3);
		while (resultSet.next()) {
			if (resultSet.getString("Id").equals(id)) {
				user.setSex(resultSet.getString("sex"));
				user.setName(resultSet.getString("name"));
				user.setId(resultSet.getString("Id"));
				user.setActivityID(resultSet.getString("activityID"));
				user.setManage(resultSet.getString("isManage"));
			}
		}
		return user;

	}

	/**
	 * 选择shift tab 整体往前捻 重置事件
	 */
	protected void rest() {
		nametf.setText("");
		passwordField.setText("");
	}

	@Override
	public void actionPerformed(ActionEvent e) {
	}
}

2.创建普通用户接口类

public class MainFrm extends JFrame {
	private JPanel contentPane;
	private JDesktopPane desktopPane;
	public static User user;

	/**
	 * Launch the application.[[
	 */

	/**
	 * Create the frame.
	 */
	MainFrm() {
		super();
	}

	public MainFrm(User user1) throws SQLException {
		this.user = user1;
		applyhave();

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 750, 580);

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu menu = new JMenu("\u7F16\u8F91");
		menuBar.add(menu);

		JMenuItem menuItem = new JMenuItem("退出");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				setDefaultCloseOperation(3);	//直接关闭程序
				System.exit(0);

			}
		});

		menu.add(menuItem);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		desktopPane = new JDesktopPane();
		desktopPane.setBackground(Color.WHITE);
		contentPane.add(desktopPane, BorderLayout.CENTER);

		JLabel label = new JLabel("用户界面");
		label.setFont(new Font("宋体", Font.BOLD, 24));
		label.setBounds(268, 103, 200, 118);
		desktopPane.add(label);

		JButton button = new JButton("查看社团信息");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Show show = new Show(user);
				show.setVisible(true);

			}
		});
		button.setBounds(15, 311, 178, 76);
		desktopPane.add(button);

		JButton button_1 = new JButton("创建社团");
		button_1.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				boolean s = false;
				CreatAct act = new CreatAct();
				act.setVisible(true);
			}
		});
		button_1.setBounds(243, 311, 178, 76);
		desktopPane.add(button_1);

		JButton button_2 = new JButton("进入管理员界面");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (user.getManage().equals("1")) {
					Manager manager;
					try {
						manager = new Manager(user);
						manager.setVisible(true);
						dispose();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					JOptionPane.showMessageDialog(null, "登录成功");
				} else {
					JOptionPane.showMessageDialog(null, "您没有权限");
				}

			}
		});
		button_2.setBounds(483, 311, 178, 76);
		desktopPane.add(button_2);
		this.setLocationRelativeTo(null);

	}

	private void applyhave() throws SQLException {
		String url = "jdbc:mysql://localhost:3306/student?useSSL=false&useUnicode=true&characterEncoding=utf8";// url是固定的
		String user3 = "root";// 这里一般是root
		String password = "root";// 这是登陆数据库的密码,我的密码为空

		String word3 = "select * from applyhave";

		ResultSet resultSet = null;

		String anameString = new String();
		Connection con = (Connection) DriverManager.getConnection(url, user3, password);// 创建连接对象,来连接数据库
		PreparedStatement ps0 = con.prepareStatement(word3);// 创建执行对象
		resultSet = ps0.executeQuery(word3);
		while (resultSet.next()) {
			if (resultSet.getString("Stuname").equals(user.getName())) {
				if (resultSet.getString("result").equals("1")) { 	
					JOptionPane.showMessageDialog(null, "您申请加入的社团申请成功");
					String word5 = "DELETE FROM applyhave WHERE Stuname = '" + user.getName() + "'";
					PreparedStatement ps4 = con.prepareStatement(word5);// 创建执行对象
					ps4.executeUpdate();
					ps4.close();
					
				}
	
		}
			}
		}
	}
}

3.创建查看社团信息类JFrame

public class Show extends JFrame {
	private JTable table;
	private User user;
	public Show(User user) {
		this.user=user;
		setFocusable(true);
		setBounds(100, 100, 1002, 697);
		
		JScrollPane scrollPane = new JScrollPane();
		
		JButton btnNewButton = new JButton("申请加入社团");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ApplyAct applyAct =new ApplyAct(user);
				applyAct.setVisible(true);
			}
		});
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(180)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 612, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(188, Short.MAX_VALUE))
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addContainerGap(771, Short.MAX_VALUE)
					.addComponent(btnNewButton)
					.addGap(86))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(125)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 348, GroupLayout.PREFERRED_SIZE)
					.addGap(57)
					.addComponent(btnNewButton)
					.addContainerGap(82, Short.MAX_VALUE))
		);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u793E\u56E2\u540D", "\u793E\u56E2\u4FE1\u606F", "\u793E\u56E2ID", "\u56E2\u957F", "\u662F\u5426\u6EE1\u5458"
			}
		));
		scrollPane.setViewportView(table);
		getContentPane().setLayout(groupLayout);
		loadData();//传入数据
		this.setLocationRelativeTo(null);
	}
	
	
//	将数据库中数据传入中可以发挥
	private void loadData() {
//		获取表格数据
		DefaultTableModel model = (DefaultTableModel) table.getModel();
//		每次添加的时候清空表格的原始数据
		model.setRowCount(0);
//		模拟数据
//		model.addRow("社团名称,社团人数,团长,是否满员");
		model.setRowCount(0);
		String url="jdbc:mysql://localhost:3306/student?useSSL=false&useUnicode=true&characterEncoding=utf8";//url是固定的 jdbc:mysql://localhost:3036/数据库名
        String user3="root";//这里一般是root
        String password="root";//这是登陆数据库的密码,我的密码为空
      
        String word="select * from activity";
        try {
            Class.forName("com.mysql.jdbc.Driver");//加载驱动类
            Connection con= DriverManager.getConnection(url, user3, password);//创建连接对象,来连接数据库
            ResultSet resultSet =null;
            PreparedStatement ps=con.prepareStatement(word);//创建执行对象
				resultSet=ps.executeQuery();
				while (resultSet.next()) {
					Object[] objs1 = {resultSet.getString("ActInfo"),resultSet.getString("ActId"),resultSet.getString("ManagerId"),resultSet.getString("Adtname"),"否"};
					model.addRow(objs1);
				}
				
			
            ps.close();
            con.close();
        } catch (ClassNotFoundException e2) {    //这里是错误捕捉,如果出错,计算机就会执行这段代码,下面的也是
            e2.printStackTrace();
        } catch (SQLException e1) {
            e1.printStackTrace();
        }
			dispose();
		
	}
}

4.创建其他功能JFrame与上述方法同,因代码过于多,不一一展示

在这里插入图片描述

  • 6
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
Java Swing是一种用于构建图形用户界面(GUI)的Java库,SQL是一种用于管理关系型数据库的查询语言。学生社团管理系统是一种针对学生社团的信息管理系统。 在Java Swing中,可以使用各种组件和容器来创建用户界面,比如按钮、文本框、表格等。可以利用这些组件设计一个直观友好的用户界面,方便用户进行查询、添加、删除和修改等操作。 在学生社团管理系统中,可以利用SQL来存储和管理学生信息、社团信息以及成员等相关数据。可以使用SQL语句来创建表格、插入数据、更新数据和查询数据等。例如,可以创建一个学生表格,其中包含学生的学号、姓名、性别等信息,还可以创建一个社团表格,其中包含社团的名称、成立时间、简介等信息。通过使用SQL,可以方便地对这些数据进行管理和操作。 学生社团管理系统可以提供以下功能:学生信息管理,包括添加学生信息、修改学生信息、删除学生信息和查询学生信息;社团信息管理,包括添加社团信息、修改社团信息、删除社团信息和查询社团信息;成员管理,包括添加成员、删除成员和查询成员等。 通过Java Swing和SQL的结合,可以开发一个功能完善、界面友好的学生社团管理系统。用户可以通过系统方便地添加、修改和删除学生信息和社团信息,还可以轻松地查询相关信息。这样的系统可以提高学生社团管理的效率,同时也方便学生参与社团活动的管理。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值