基于java+mysql的swing+mysql学生管理系统java基础gui(java+gui)

基于java+mysql的swing+mysql学生管理系统java基础gui(java+gui)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于java+mysql的Swing+MySQL学生管理系统java基础gui(java+gui)

功能介绍:

学生信息管理,姓名,编号,性别,成绩,学号住址

	 * @throws Exception
	 */
	public int delete(Connection con,String id)throws Exception{
		String sql="delete from t_school_class where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, id);
		return pstmt.executeUpdate();
	}
	
	/**
	 * 更新班级
	 * @param con
	 * @param schoolClass
	 * @return
	 * @throws Exception
	 */
	public int update(Connection con,SchoolClass schoolClass)throws Exception{
		String sql="update t_school_class set className=?,classDesc=? where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, schoolClass.getClassName());
		pstmt.setString(2, schoolClass.getCalssDesc());
		pstmt.setInt(3, schoolClass.getId());
		return pstmt.executeUpdate();
	}
}

/**
 * 学生实体
 *
 */
public class Student {

	private int id; // 编号
	private String name; // 姓名
	private String sn; // 学号
	private String sex; // 性别
	private String dept; // 成绩
	private Integer classId; // 班级Id

	public String getCalssDesc() {
		return calssDesc;
	}

	public void setCalssDesc(String calssDesc) {
		this.calssDesc = calssDesc;
	}

	@Override
	public String toString() {
		return className;
	}

	
}

/**
 * 用户Dao类
 *
 */
public class UserDao {

	/**
	 * 登录验证
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public User login(Connection con,User user)throws Exception{
		User resultUser=null;
	
	
	
	public Student(String name, String sn, String sex, String dept, Integer calssId, String address) {
		super();
		this.name = name;
		this.sn = sn;
		this.sex = sex;
		this.dept = dept;
		this.classId = calssId;
		this.address = address;
	}

	

	public Student(int id, String name, String sn, String sex, String dept, Integer calssId, String address) {
		super();
		this.id = id;
		this.name = name;
		this.sn = sn;
		this.sex = sex;
		this.dept = dept;
		this.classId = calssId;
		this.address = address;
	}

	public Student(String name, String sn, Integer calssId) {
		super();
		this.name = name;
		this.sn = sn;
		this.classId = calssId;
	}

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
		
		addressTxt = new JTextArea();
		
		JLabel label_5 = new JLabel("所在班级");
		
	    schoolClassJcb = new JComboBox();
	    gradeTxt = new JTextField();
	    gradeTxt.setColumns(10);
		JButton button = new JButton("添加");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				bookAddActionPerformed(e);
			}
		});
		button.setIcon(new ImageIcon(StudentAddInterFrm.class.getResource("/images/add.png")));
		
		JButton button_1 = new JButton("重置");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				resetValueActionPerformed(e);
			}
		});
		button_1.setIcon(new ImageIcon(StudentAddInterFrm.class.getResource("/images/reset.png")));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(42)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(button)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(button_1)
							.addGap(232))
						.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
							.addComponent(label_5)
							.addGroup(groupLayout.createSequentialGroup()
								.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
									.addComponent(label_4)
									.addComponent(label_2)
									.addComponent(label))
								.addPreferredGap(ComponentPlacement.RELATED)
								.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
									.addGroup(groupLayout.createSequentialGroup()
										.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
											.addComponent(studentTxt, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
											.addGroup(groupLayout.createSequentialGroup()
												.addComponent(manJrb)
												.addPreferredGap(ComponentPlacement.UNRELATED)
												.addComponent(femaleJrb))
											.addComponent(schoolClassJcb, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
										.addGap(35)
										.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
											.addGroup(groupLayout.createSequentialGroup()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1.createSequentialGroup()
							.addComponent(button_1)
							.addGap(18)
							.addComponent(button_2)
							.addGap(386))
						.addGroup(gl_panel_1.createSequentialGroup()
							.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panel_1.createSequentialGroup()
									.addComponent(label_6)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(addressTxt))
								.addGroup(gl_panel_1.createSequentialGroup()
									.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(label_4)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(deptTxt))
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(lblNewLabel)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(idTxt, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)))
									.addGap(26)
									.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(lblNewLabel_1)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(nameTxt, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE))
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(lblNewLabel_2)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(snTxt)))
									.addGap(26)
									.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(label_3)
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addComponent(manJrb)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(femaleJrb))
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(label_5)
											.addPreferredGap(ComponentPlacement.UNRELATED)

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getDept() {
		return dept;
	}

	public void setDept(String dept) {
		this.dept = dept;
	}

	public Integer getClassId() {
		return classId;
	}

	public void setClassId(Integer classId) {
		this.classId = classId;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getAddress() {
		mnNewMenu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/base.png")));
		menuBar.add(mnNewMenu);
		
		JMenu mnNewMenu_1 = new JMenu("班级信息管理");
		mnNewMenu_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookTypeManager.png")));
		mnNewMenu.add(mnNewMenu_1);
		
		JMenuItem menuItem = new JMenuItem("班级信息添加");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SchoolClassAddInterFrm bookTypeAddInterFrm=new SchoolClassAddInterFrm();
				bookTypeAddInterFrm.setVisible(true);
				table.add(bookTypeAddInterFrm);
			}
		});
		menuItem.setIcon(new ImageIcon(MainFrm.class.getResource("/images/add.png")));
		mnNewMenu_1.add(menuItem);
		
		JMenuItem menuItem_1 = new JMenuItem("班级信息整改");
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SchoolClassManageInterFrm bookTypeManageInterFrm=new SchoolClassManageInterFrm();
				bookTypeManageInterFrm.setVisible(true);
				table.add(bookTypeManageInterFrm);
			}
		});
		menuItem_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/edit.png")));
		mnNewMenu_1.add(menuItem_1);
		
		JMenu mnNewMenu_2 = new JMenu("学生信息管理");
		mnNewMenu_2.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookManager.png")));
		mnNewMenu.add(mnNewMenu_2);
		
		JMenuItem menuItem_2 = new JMenuItem("学生信息添加");
		menuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				StudentAddInterFrm bookAddInterFrm=new StudentAddInterFrm();
				bookAddInterFrm.setVisible(true);
				table.add(bookAddInterFrm);
			}
		});

		menuItem_2.setIcon(new ImageIcon(MainFrm.class.getResource("/images/add.png")));
		mnNewMenu_2.add(menuItem_2);
		
		JMenuItem menuItem_3 = new JMenuItem("学生信息整改");
		menuItem_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				StudentManageInterFrm bookManageInterFrm=new StudentManageInterFrm();
				bookManageInterFrm.setVisible(true);
				table.add(bookManageInterFrm);
			}
							.addGap(386))
						.addGroup(gl_panel_1.createSequentialGroup()
							.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panel_1.createSequentialGroup()
									.addComponent(label_6)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(addressTxt))
								.addGroup(gl_panel_1.createSequentialGroup()
									.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(label_4)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(deptTxt))
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(lblNewLabel)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(idTxt, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)))
									.addGap(26)
									.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(lblNewLabel_1)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(nameTxt, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE))
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(lblNewLabel_2)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(snTxt)))
									.addGap(26)
									.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(label_3)
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addComponent(manJrb)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(femaleJrb))
										.addGroup(gl_panel_1.createSequentialGroup()
											.addComponent(label_5)
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addComponent(schoolClassJcb, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
							.addContainerGap(86, Short.MAX_VALUE))))
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGap(21)
			}else{
				JOptionPane.showMessageDialog(null, "修改失败");
			}
		}catch(Exception e){
			e.printStackTrace();
			JOptionPane.showMessageDialog(null, "修改失败");
		}finally{
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * 表格行点击事件处理
	 * @param e
	 */
	private void schoolClassTableMousePressed(MouseEvent evt) {
		int row=schoolClassTable.getSelectedRow();
		idTxt.setText((String)schoolClassTable.getValueAt(row, 0));
		classNameTxt.setText((String)schoolClassTable.getValueAt(row, 1));
		classDescTxt.setText((String)schoolClassTable.getValueAt(row, 2));
	}

	/**
	 * 班级信息搜索事件处理
	 * @param evt
	 */
	private void schoolClassSearchActionPerformed(ActionEvent evt) {
		String s_className=this.s_classNameTxt.getText();
		SchoolClass schoolClass=new SchoolClass();
		schoolClass.setClassName(s_className);
		this.fillTable(schoolClass);
	}

	/**
	 * 初始化表格
	 * @param schoolClass
	 */
	private void fillTable(SchoolClass schoolClass){
		DefaultTableModel dtm=(DefaultTableModel) schoolClassTable.getModel();
		dtm.setRowCount(0); // 设置成0行
		Connection con=null;
		try{
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	
}

/**
 * 字符串工具类
 *
 */
public class StringUtil {

	/**
	 * 判断是否是空
	 * @param str
	 * @return
	 */
	public static boolean isEmpty(String str){
		if(str==null || "".equals(str.trim())){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 判断是否不是空
	 * @param str
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 初始化表格数据
	 * @param book
	 */
	private void fillTable(Student book){
		DefaultTableModel dtm=(DefaultTableModel) studentTable.getModel();
		dtm.setRowCount(0); // 设置成0行
		Connection con=null;
		try{
			con=dbUtil.getCon();
			ResultSet rs=studentDao.list(con, book);
			while(rs.next()){
				Vector v=new Vector();
				v.add(rs.getString("id"));
				v.add(rs.getString("name"));
				v.add(rs.getString("sn"));
				v.add(rs.getString("sex"));
				v.add(rs.getString("dept"));
				v.add(rs.getString("address"));
				v.add(rs.getString("className"));
				dtm.addRow(v);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}

						.addComponent(btnNewButton_1))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		panel.setLayout(gl_panel);
		
		schoolClassTable = new JTable();
		schoolClassTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				schoolClassTableMousePressed(e);
			}
		});
		schoolClassTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u7F16\u53F7", "班级信息名称", "班级信息描述"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		schoolClassTable.getColumnModel().getColumn(1).setPreferredWidth(110);
		schoolClassTable.getColumnModel().getColumn(2).setPreferredWidth(123);
		scrollPane.setViewportView(schoolClassTable);
		getContentPane().setLayout(groupLayout);
		
		this.fillTable(new SchoolClass());

		// 设置文本域边框
	    classDescTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false));
	}
	
	/**
	 * 班级信息删除事件处理
	 * @param e
	 */
	private void schoolClassDeleteActionEvent(ActionEvent evt) {
		String id=idTxt.getText();
		if(StringUtil.isEmpty(id)){
			JOptionPane.showMessageDialog(null, "请选择要删除的记录");
			return;
		}
		int n=JOptionPane.showConfirmDialog(null, "确定要删除该记录吗?");
		if(n==0){
			Connection con=null;
			try{
		pstmt.setString(2, student.getSn());
		pstmt.setString(3, student.getSex());
		pstmt.setString(4, student.getDept());
		pstmt.setInt(5, student.getClassId());
		pstmt.setString(6, student.getAddress());
		return pstmt.executeUpdate();
	}
	
	/**
	 * 学生信息查询
	 * @param con
	 * @param student
	 * @return
	 * @throws Exception
	 */
	public ResultSet list(Connection con,Student student)throws Exception{
		StringBuffer sb=new StringBuffer("select * from t_student b,t_school_class bt where b.classId=bt.id");
		if(StringUtil.isNotEmpty(student.getName())){
			sb.append(" and b.name like '%"+student.getName()+"%'");
		}
		if(StringUtil.isNotEmpty(student.getSn())){
			sb.append(" and b.sn like '%"+student.getSn()+"%'");
		}
		if(student.getClassId()!=null && student.getClassId()!=-1){
			sb.append(" and b.classId="+student.getClassId());
		}
		PreparedStatement pstmt=con.prepareStatement(sb.toString());
		return pstmt.executeQuery();
	}
	
	/**
	 * 学生信息删除
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public int delete(Connection con,String id)throws Exception{
		String sql="delete from t_student where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, id);
		return pstmt.executeUpdate();
	}
	
	private void schoolClassDeleteActionEvent(ActionEvent evt) {
		String id=idTxt.getText();
		if(StringUtil.isEmpty(id)){
			JOptionPane.showMessageDialog(null, "请选择要删除的记录");
			return;
		}
		int n=JOptionPane.showConfirmDialog(null, "确定要删除该记录吗?");
		if(n==0){
			Connection con=null;
			try{
				con=dbUtil.getCon();
				boolean flag=studentDao.existStudentByclassId(con, id);
				if(flag){
					JOptionPane.showMessageDialog(null, "当前班级信息下有图书,不能删除");
					return;
				}
				int deleteNum=schoolClassDao.delete(con, id);
				if(deleteNum==1){
					JOptionPane.showMessageDialog(null, "删除成功");
					this.resetValue();
					this.fillTable(new SchoolClass());
				}else{
					JOptionPane.showMessageDialog(null, "删除失败");
				}
			}catch(Exception e){
				e.printStackTrace();
				JOptionPane.showMessageDialog(null, "删除失败");
			}finally{
				try {
					dbUtil.closeCon(con);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

	/**
	 * 班级信息修改事件处理
	 * @param evt
	 */
	private void schoolClassUpdateActionEvent(ActionEvent evt) {
		String id=idTxt.getText();
		String className=classNameTxt.getText();
		String classDesc=classDescTxt.getText();

	private JPanel contentPane;
	private JDesktopPane table =null;

	/**
	 * Create the frame.
	 */
	public MainFrm() {
		setTitle("学生信息管理系统主界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("基本数据维护");
		mnNewMenu.setIcon(new ImageIcon(MainFrm.class.getResource("/images/base.png")));
		menuBar.add(mnNewMenu);
		
		JMenu mnNewMenu_1 = new JMenu("班级信息管理");
		mnNewMenu_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookTypeManager.png")));
		mnNewMenu.add(mnNewMenu_1);
		
		JMenuItem menuItem = new JMenuItem("班级信息添加");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SchoolClassAddInterFrm bookTypeAddInterFrm=new SchoolClassAddInterFrm();
				bookTypeAddInterFrm.setVisible(true);
				table.add(bookTypeAddInterFrm);
			}
		});
		menuItem.setIcon(new ImageIcon(MainFrm.class.getResource("/images/add.png")));
		mnNewMenu_1.add(menuItem);
		
		JMenuItem menuItem_1 = new JMenuItem("班级信息整改");
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SchoolClassManageInterFrm bookTypeManageInterFrm=new SchoolClassManageInterFrm();
				bookTypeManageInterFrm.setVisible(true);
				table.add(bookTypeManageInterFrm);
			}
		});
		menuItem_1.setIcon(new ImageIcon(MainFrm.class.getResource("/images/edit.png")));
		mnNewMenu_1.add(menuItem_1);
		
		JMenu mnNewMenu_2 = new JMenu("学生信息管理");
		mnNewMenu_2.setIcon(new ImageIcon(MainFrm.class.getResource("/images/bookManager.png")));
		buttonGroup.add(femaleJrb);
		
		JLabel label_4 = new JLabel("成绩分数");
		
		deptTxt = new JTextField();
		deptTxt.setColumns(10);
		
		JLabel lblNewLabel_2 = new JLabel("学生学号");
		
		snTxt = new JTextField();
		snTxt.setColumns(10);
		
		JLabel label_5 = new JLabel("所属班级");
		
		schoolClassJcb = new JComboBox();
		
		JLabel label_6 = new JLabel("家庭住址");
		
		addressTxt = new JTextArea();
		
		JButton button_1 = new JButton("\u4FEE\u6539");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				studentUpdateActionPerformed(evt);
			}
		});
		button_1.setIcon(new ImageIcon(StudentManageInterFrm.class.getResource("/images/modify.png")));
		
		JButton button_2 = new JButton("\u5220\u9664");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				studentDeleteActionPerformed(evt);
			}
		});
		button_2.setIcon(new ImageIcon(StudentManageInterFrm.class.getResource("/images/delete.png")));
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGap(19)
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel_1.createSequentialGroup()
							.addComponent(button_1)
							.addGap(18)
							.addComponent(button_2)
							.addGap(386))
						.addGroup(gl_panel_1.createSequentialGroup()
							.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_panel_1.createSequentialGroup()
									.addComponent(label_6)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(addressTxt))
								.addGroup(gl_panel_1.createSequentialGroup()
									.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false)
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 初始化表格数据
	 * @param book
	 */
	private void fillTable(Student book){
		DefaultTableModel dtm=(DefaultTableModel) studentTable.getModel();
		dtm.setRowCount(0); // 设置成0行
		Connection con=null;
		try{
			con=dbUtil.getCon();
			ResultSet rs=studentDao.list(con, book);
			while(rs.next()){
				Vector v=new Vector();
				v.add(rs.getString("id"));
				v.add(rs.getString("name"));
				v.add(rs.getString("sn"));
				v.add(rs.getString("sex"));
				v.add(rs.getString("dept"));
				v.add(rs.getString("address"));
				v.add(rs.getString("className"));
				dtm.addRow(v);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		schoolClassTable = new JTable();
		schoolClassTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				schoolClassTableMousePressed(e);
			}
		});
		schoolClassTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u7F16\u53F7", "班级信息名称", "班级信息描述"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		schoolClassTable.getColumnModel().getColumn(1).setPreferredWidth(110);
		schoolClassTable.getColumnModel().getColumn(2).setPreferredWidth(123);
		scrollPane.setViewportView(schoolClassTable);
		getContentPane().setLayout(groupLayout);
		
		this.fillTable(new SchoolClass());

		// 设置文本域边框
	    classDescTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false));
	}
	
	/**
	 * 班级信息删除事件处理
	 * @param e
	 */
	private void schoolClassDeleteActionEvent(ActionEvent evt) {
		String id=idTxt.getText();
		if(StringUtil.isEmpty(id)){
			JOptionPane.showMessageDialog(null, "请选择要删除的记录");
			return;
		}
		int n=JOptionPane.showConfirmDialog(null, "确定要删除该记录吗?");
		if(n==0){
			Connection con=null;
			try{
				con=dbUtil.getCon();
				boolean flag=studentDao.existStudentByclassId(con, id);
				if(flag){
					JOptionPane.showMessageDialog(null, "当前班级信息下有图书,不能删除");
					return;
				}

请添加图片描述

请添加图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java Swing MySQL JDBC GUI小区物业管理系统是一个基于Java Swing界面开发框架,使用MySQL数据库连接和操作的物业管理系统。该系统旨在帮助小区物业管理部门高效地管理小区的各项事务和服务。 系统的主要功能包括小区住户信息管理、缴费管理、报修管理、公告发布、物业费用统计等。 在小区住户信息管理方面,管理员可以通过系统录入住户的基本信息,包括姓名、联系方式、房屋信息等,也可以进行住户信息的查询和修改。同时,住户可以通过该系统进行自己基本信息的查看和修改。 缴费管理是该系统的另一个重要功能。住户可以通过系统查询到自己应缴纳的各项费用,并进行在线缴费。管理员可以查看住户的缴费状态和历史记录,自动生成每个月的物业费用明细。 报修管理功能允许住户在线提交报修请求,管理员可以对报修请求进行处理和跟踪。管理员可以指派维修人员进行维修,并跟踪维修进度和记录维修结果。 公告发布功能允许管理员发布通知和公告,住户可以通过系统查看最新的公告和通知,保持信息的及时性和准确性。 物业费用统计功能可统计小区的每个月物业费用的收入情况,方便管理员进行费用管理和财务分析。 总之,该系统通过使用Java Swing提供美观的用户界面,利用MySQL JDBC连接数据库实现数据的存储和查询,为小区物业管理部门提供了一个便捷、高效的管理平台。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值