java实现简易社团管理系统.zip
立即下载
资源介绍:
简易社团管理系统包括社团事务管理,基础申请,学生信息管理,密码管理功能,通过java和mysql实现(里面包括源码和数据库文件)
package 社团manage;
import java.awt.BorderLayout;
import java.awt.Color;
/*
* 学生信息查询界面
*/
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
@SuppressWarnings("serial")
public class membersManage extends JFrame {
public int i = 0;
public membersManage() {
setTitle("学生信息查询界面");
Container container = getContentPane();
container.setLayout(new GridLayout(4, 1));
setBounds(20, 20, 900, 1000);
JLabel jl1 = new JLabel("学号:"); // 标签
JTextField jt1 = new JTextField();
JButton jb1 = new JButton("查询");// 查询按钮
JButton jb2 = new JButton("更新");
JButton jb3 = new JButton("删除");
JButton jb4 = new JButton("新增");
JPanel panel1 = new JPanel();
panel1.setBorder(BorderFactory.createTitledBorder("管理面板"));
panel1.setLayout(null);
JLabel jl2 = new JLabel("学号:");
JLabel jl3 = new JLabel("姓名:");
JLabel jl4 = new JLabel("班级:");
JLabel jl5 = new JLabel("性别:");
JLabel jl6 = new JLabel("院系:");
JLabel jl7 = new JLabel("专业:");
JLabel jl8 = new JLabel("所属社团:");
JTextField jt2 = new JTextField();
JTextField jt3 = new JTextField();
JTextField jt4 = new JTextField();
JTextField jt5 = new JTextField();
JTextField jt6 = new JTextField();
JTextField jt7 = new JTextField();
JTextField jt8 = new JTextField();
JTextField jt9 = new JTextField();
jl1.setBounds(50, 100, 70, 30);// 学号标签
jt1.setBounds(90, 100, 100, 30);
jb1.setBounds(200, 100, 70, 30);// 查询按钮
jb2.setBounds(650, 30, 70, 30); // 更新按钮
jb3.setBounds(650, 90, 70, 30);// 删除
jb4.setBounds(650, 150, 70, 30);// 新增
jl2.setBounds(300, 30, 70, 30); // 学号
jt2.setBounds(340, 30, 100, 30);
jl3.setBounds(300, 80, 70, 30);// 姓名
jt3.setBounds(340, 80, 100, 30);
jl4.setBounds(300, 130, 70, 30);// 班级
jt4.setBounds(340, 130, 100, 30);
jl5.setBounds(300, 180, 70, 30); // 性别
jt5.setBounds(340, 180, 100, 30);
jl6.setBounds(470, 30, 70, 30);// 院系
jt6.setBounds(510, 30, 100, 30);
jl7.setBounds(470, 80, 70, 30);// 专业
jt7.setBounds(510, 80, 100, 30);
jl8.setBounds(450, 130, 70, 30);// 所属社团
jt8.setBounds(510, 130, 100, 30);
panel1.add(jl1);
panel1.add(jt1);
panel1.add(jb1);
panel1.add(jb2);
panel1.add(jb3);
panel1.add(jb4);
panel1.add(jl2);
panel1.add(jl3);
panel1.add(jl4);
panel1.add(jl5);
panel1.add(jl6);
panel1.add(jl7);
panel1.add(jl8);
panel1.add(jt2);
panel1.add(jt3);
panel1.add(jt4);
panel1.add(jt5);
panel1.add(jt6);
panel1.add(jt7);
panel1.add(jt8);
jb1.addActionListener(new ActionListener() {// 查询按钮触发
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
mysql testmysql = new mysql();// 实例化连接测试类的对象
// refresh.tan();
String str9 = "select sno from member where sno='" + jt1.getText() + "'"; // 根据学号查询
String str10 = null;
try {
mysql.sql = mysql.con.createStatement();// 插入之前先在数据库里面查
mysql.res = mysql.sql.executeQuery(str9);
while (mysql.res.next()) {
str10 = mysql.res.getString("sno");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
if (str10 != null) {
try {
String str1 = "select * from member where sno='" + jt1.getText() + "'"; // 根据学号查询
String str2, str3, str4, str5, str6, str7, str8;
mysql.sql = mysql.con.createStatement();
mysql.res = mysql.sql.executeQuery(str1);
int number = 0;
while (mysql.res.next()) {
str2 = mysql.res.getString(1);
str3 = mysql.res.getString(2);
str4 = mysql.res.getString(3);
str5 = mysql.res.getString(4);
str6 = mysql.res.getString(5);
str7 = mysql.res.getString(6);
str8 = mysql.res.getString(7);
number++;
jt2.setText(str2);
jt3.setText(str3);
jt4.setText(str4);
jt5.setText(str5);
jt6.setText(str6);
jt7.setText(str7);
jt8.setText(str8);
}
mysql.res.absolute(0);// 移动指针
String[][] tables = new String[number][7];
i = 0;
while (mysql.res.next()) {
int j = 0;
tables[i][j++] = mysql.res.getString(1);
tables[i][j++] = mysql.res.getString(2);
tables[i][j++] = mysql.res.getString(3);
tables[i][j++] = mysql.res.getString(4);
tables[i][j++] = mysql.res.getString(5);
tables[i][j++] = mysql.res.getString(6);
tables[i++][j++] = mysql.res.getString(7);
number++;
}
String[] column = { "学号", "姓名", "班级", "性别", "院系", "专业", "所属社团" };
JTable testtable = new JTable(tables, column); // 指定列名和数据的表格
testtable.setSelectionBackground(Color.yellow);
JScrollPane scrollPane = new JScrollPane(testtable);// 创建显示表格的滚动面板
scrollPane.setBorder(BorderFactory.createTitledBorder("学生信息"));
container.add(scrollPane, BorderLayout.CENTER);
validate();
} catch (SQLException e1) {
e1.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(null, "学号不存在");
}
}
});
jb2.addActionListener(new ActionListener() {// 更新按钮触发
@Override
public void actionPerformed(ActionEvent e) {
String str1, str2, str3, str4, str5, str6, str7;
str1 = jt2.getText();
str2 = jt3.getText();
str3 = jt4.getText();
str4 = jt5.getText();
str5 = jt6.getText();
str6 = jt7.getText();
str7 = jt8.getText();
String str8 = "update member set name=?,clname=?,sex=?,department=?,sdept=?,community=? where sno='"
+ jt1.getText() + "'";
try {
mysql.con = mysql.connection();
PreparedStatement sql = mysql.con.prepareStatement(str8);
sql.setString(1, str2);
sql.setString(2, str3);
sql.setString(3, str4);
sql.setString(4, str5);
sql.setString(5, str6);
sql.setString(6, str7);
int result = sql.executeUpdate();
// System.out.println("有" + result + "行记录被修改");
validate();
} catch (SQLException e1) {
e1.printStackTrace();
}
String[] column = { "学号", "姓名", "班级", "性别", "院系", "专业", "所属院系" };
String[][] tables = { { str1, str2, str3, str4, str5, str6, str7 } };
JTable table = new JTable(tables, column);
JScrollPane scrollpane2 = new JScrollPane(table);
scrollpane2.setBorder(BorderFactory.createTitledBorder("新信息"));
container.add(scrollpane2, BorderLayout.CENTER);// 将滚动面板添加到边界布局的中间
JOptionPane.showMessageDialog(null, "更新成功");
validate();
// MainFrame.update();
}
/*
* else { JOptionPane.showMessageDialog(null, "更新失败"); } }
*/
});
jb3.addActionListener(new ActionListener() {// 删除按钮事件监听器
public void actionPerformed(ActionEvent e) {
String str1 = jt2.getText();
String str2 = "delete from member where sno='" + str1 + "'";
System.out.println(str2);
try {
mysql.con = mysql.connection();
PreparedStatement sql = mysql.con.prepareStatement(str2);
int result = sql.executeUpdate();
JOptionPane.showMessageDialog(null, "删除成功");
// System.out.println("有" + result + "行记录被删除");
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
jb4.addActionListener(new ActionListener() {// 新增按钮事件监听器
public void actionPerformed(Act