学生信息管理系统8

SCM.java

import java.awt.Component;

import java.awt.FlowLayout;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
class SCM extends JFrame implements ActionListener {
JPanel p = new JPanel();
JButton btnSearch = new JButton("查询");
JButton btnDisplay = new JButton("显示");
JMenuBar mb = new JMenuBar();
JPanel p1 = new JPanel();;
JTable sTable;
JScrollPane scroll;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Object[][] playerInfo;
SCSelect scst;
String mscxh = null;
int ii = 0;
boolean bstd = false;

SCM(String title) {
super(title);
add("South", p);
this.add("Center", p1);
mb.add(btnSearch);
mb.add(btnDisplay);
this.connDB();
this.setBounds(200, 200, 400, 260);
btnSearch.addActionListener(this);
btnDisplay.addActionListener(this);
this.setJMenuBar(mb);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
show();
}
SCM(SCSelect scst, String title) {
super(title);
this.scst = scst;
bstd = true;
add("South", p);
this.add("Center", p1);
mb.add(btnSearch);
mb.add(btnDisplay);
this.connDB();
this.setBounds(200, 200, 400, 260);
btnSearch.addActionListener(this);
btnDisplay.addActionListener(this);
this.setJMenuBar(mb);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
show();
}
public void display() {
int i = 0;
int j = 0;
int k = 0;
List al = new ArrayList();
try {
rs = stmt.executeQuery("select * from sc");
while (rs.next()) {
al.add(rs.getString("sno"));
al.add(rs.getString("cno"));
al.add(rs.getString("g"));
i++;
}
} catch (SQLException e) {
e.printStackTrace();
}
playerInfo = new Object[i][3];
String[] columnNames = { "学号", "课程号", "成绩" };
try {
rs = stmt.executeQuery("select * from sc order by sno");
while (rs.next()) {
playerInfo[j][0] = rs.getString("sno");
playerInfo[j][1] = rs.getString("cno");
playerInfo[j][2] = rs.getString("g");
j++;
}
} catch (SQLException e) {
e.printStackTrace();
}
sTable = new JTable(playerInfo, columnNames);
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
}


public void connDB() { 
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/student",
"root", "123456");
stmt = con.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
}

public void closeDB() 
{
try {
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

public void select() {
ii = scst.i;
mscxh = scst.scxh;
int j = 0;
playerInfo = new Object[ii][3];
String[] columnNames = { "学号", "课程号", "成绩" };
try {
rs = stmt
.executeQuery("select * from sc where sno='" + mscxh + "'");
while (rs.next()) {
playerInfo[j][0] = rs.getString("sno");
playerInfo[j][1] = rs.getString("cno");
playerInfo[j][2] = rs.getString("g");
j++;
}
} catch (SQLException e) {
e.printStackTrace();
}
if (playerInfo[0][1] == null) {
this.dispose();
JOptionPane.showMessageDialog(null, "课程号不存在!");
new SCM("选课信息管理").display();
} else {
sTable = new JTable(playerInfo, columnNames);
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
}
}


public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "查询") {
scst = new SCSelect();
this.dispose();
}
if (e.getActionCommand() == "显示") {
this.dispose();
new SCM("选课信息管理").display();
}
}

}


GM.java

import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;


class GM extends JFrame implements ActionListener {
JPanel p = new JPanel();
JButton btnAlter = new JButton("修改成绩");
JButton btnSearch = new JButton("查询");
JButton btnDisplay = new JButton("显示");
JMenuBar mb = new JMenuBar();
JPanel p1 = new JPanel();;
JTable sTable;
JScrollPane scroll;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Object[][] playerInfo;
GSelect gst;
int ii = 0;
String mxh = null;
boolean bstd = false;

GM(String title) {
super(title);
add("South", p);
this.add("Center", p1);
mb.add(btnAlter);
mb.add(btnSearch);
mb.add(btnDisplay);
this.connDB();
this.setBounds(200, 200, 400, 260);
btnAlter.addActionListener(this);
btnSearch.addActionListener(this);
btnDisplay.addActionListener(this);
this.setJMenuBar(mb);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
show();
}

GM(GSelect gst, String title) {
super(title);
this.gst = gst;
bstd = true;
add("South", p);
this.add("Center", p1);
mb.add(btnAlter);
mb.add(btnSearch);
mb.add(btnDisplay);
this.connDB();
this.setBounds(200, 200, 400, 260);
btnAlter.addActionListener(this);
btnSearch.addActionListener(this);
btnDisplay.addActionListener(this);
this.setJMenuBar(mb);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
show();


}

public void display() {
int i = 0;
int j = 0;
int k = 0;
List al = new ArrayList();
try {
rs = stmt.executeQuery("select *  from sc,c where c.cno=sc.cno");
while (rs.next()) {// 找出表中的记录数赋给i
al.add(rs.getString("sno"));
al.add(rs.getString("cn"));
al.add(rs.getString("g"));
i++;
}
} catch (SQLException e) {
e.printStackTrace();
}
playerInfo = new Object[i][3];
String[] columnNames = { "学号", "课程名", "成绩" };


try {
rs = stmt.executeQuery("select *  from sc,c where c.cno=sc.cno");
while (rs.next()) {
playerInfo[j][0] = rs.getString("sno");
playerInfo[j][1] = rs.getString("cn");
playerInfo[j][2] = rs.getString("g");
j++;
}
} catch (SQLException e) {
e.printStackTrace();
}
sTable = new JTable(playerInfo, columnNames);
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
}

public void connDB() { 
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/student",
"root", "123456");
stmt = con.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
}


public void closeDB() 
{
try {
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}


public void update() {
String kch = null;
String kcm = null;
String xxkch = null;
int row = -1;
row = sTable.getSelectedRow();
if (row == -1) {
JOptionPane.showMessageDialog(null, "请选择要修改的记录!");
} else {
int j1 = 0;
try {
if (!bstd) {
rs = stmt
.executeQuery("select *  from sc,c where c.cno=sc.cno");
} else {
rs = stmt
.executeQuery("select *  from sc,c where c.cno=sc.cno and sno='"
+ mxh + "'");
}
while (rs.next() && j1 <= row) {
kch = rs.getString("sno");
kcm = rs.getString("cn");
xxkch = rs.getString("g");
j1++;
}
} catch (SQLException e) {
e.printStackTrace();
}
GAdd gadd = new GAdd();
gadd.setTitle("修改成绩");
gadd.tcno.setText(kch);
gadd.tcname.setText(kcm);
gadd.tpcno.setText(xxkch);
gadd.tcno.setEnabled(false);
gadd.tcname.setEnabled(false);
this.dispose();
}
}


public void select() {
int j = 0;
ii = gst.i;
mxh = gst.gxh;
playerInfo = new Object[ii][3];
String[] columnNames = { "学号", "课程名", "成绩" };
try {
rs = stmt
.executeQuery("select *  from sc,c where c.cno=sc.cno and sno='"
+ mxh + "'");
while (rs.next()) {
playerInfo[j][0] = rs.getString("sno");
playerInfo[j][1] = rs.getString("cn");
playerInfo[j][2] = rs.getString("g");
j++;
}
} catch (SQLException e) {
e.printStackTrace();
}
if (playerInfo[0][1] == null) {
this.dispose();
JOptionPane.showMessageDialog(null, "学号不存在!");
new GM("成绩信息管理").display();
} else {
sTable = new JTable(playerInfo, columnNames);
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
}
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "修改成绩") {
this.update();
}
if (e.getActionCommand() == "查询") {
gst = new GSelect();
this.dispose();
}
if (e.getActionCommand() == "显示") {
this.dispose();
new GM("成绩信息管理").display();
}
}
}


PM.java

import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;

class PM extends JFrame implements ActionListener {
JPanel p = new JPanel();
JButton btnAlter = new JButton("修改");
JButton btnSearch = new JButton("查询");
JButton btnDisplay = new JButton("显示");
JMenuBar mb = new JMenuBar();
JPanel p1 = new JPanel();;
JTable sTable;
JScrollPane scroll;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Object[][] playerInfo;
PSelect pst;
String myh = null;
boolean bstd = false;


PM(String title) {
super(title);
add("South", p);
//this.add("Center", p1);
mb.add(btnAlter);
mb.add(btnSearch);
mb.add(btnDisplay);
this.connDB();
this.setBounds(200, 200, 200, 260);
btnAlter.addActionListener(this);
btnSearch.addActionListener(this);
btnDisplay.addActionListener(this);
this.setJMenuBar(mb);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
show();
}


PM(PSelect pst, String title) {
super(title);
this.pst = pst;
bstd = true;
add("South", p);
//this.add("Center", p1);
mb.add(btnAlter);
mb.add(btnSearch);
mb.add(btnDisplay);
this.connDB();
this.setBounds(200, 200, 200, 260);
btnAlter.addActionListener(this);
btnSearch.addActionListener(this);
btnDisplay.addActionListener(this);
this.setJMenuBar(mb);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
show();
}


public void display() {
int i = 0;
int j = 0;
int k = 0;
List al = new ArrayList();
try {
rs = stmt.executeQuery("select * from unpw where qx=1");
while (rs.next()) {
al.add(rs.getString("un"));
al.add(rs.getString("pw"));
i++;
}
} catch (SQLException e) {
e.printStackTrace();
}
playerInfo = new Object[i][2];
String[] columnNames = { "用户名", "密码" };


try {
rs = stmt.executeQuery("select * from unpw where qx=1 order by un");
while (rs.next()) {
playerInfo[j][0] = rs.getString("un");
playerInfo[j][1] = rs.getString("pw");
j++;
}
} catch (SQLException e) {
e.printStackTrace();
}
sTable = new JTable(playerInfo, columnNames);
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
}


public void connDB() { 
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/student",
"root", "123456");
stmt = con.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}


}


public void closeDB() 
{
try {
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

public void update() {
String yh = null;
String mm = null;
int row = -1;
row = sTable.getSelectedRow();
if (row == -1) {
JOptionPane.showMessageDialog(null, "请选择要修改的记录!");
} else {
int j1 = 0;
try {
if (!bstd) {
rs = stmt.executeQuery("select * from unpw where qx=1");
} else {
rs = stmt
.executeQuery("select * from unpw where qx=1 and un='"
+ myh + "'");
}
while (rs.next() && j1 <= row) {
yh = rs.getString("un");
mm = rs.getString("pw");
j1++;
}
} catch (SQLException e) {
e.printStackTrace();
}
UAdd uadd = new UAdd();
uadd.setTitle("修改");
uadd.tun.setText(yh);
uadd.tpw.setText(mm);
uadd.tun.setEnabled(false);
this.dispose();
}
}

public void select() {
myh = pst.yh;
playerInfo = new Object[1][2];
String[] columnNames = { "用户名", "密码" };
try {
rs = stmt.executeQuery("select * from unpw where qx=1 and un='"
+ myh + "'");
while (rs.next()) {
playerInfo[0][0] = rs.getString("un");
playerInfo[0][1] = rs.getString("pw");
}
} catch (SQLException e) {
e.printStackTrace();
}
if (playerInfo[0][1] == null) {
this.dispose();
JOptionPane.showMessageDialog(null, "用户不存在!");
new PM("用户信息管理").display();
} else {
sTable = new JTable(playerInfo, columnNames);
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
}
}

public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "修改") {
this.update();
}
if (e.getActionCommand() == "查询") {
pst = new PSelect();
this.dispose();
}
if (e.getActionCommand() == "显示") {
this.dispose();
new PM("用户信息管理").display();
}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值