package body;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import course.AddCourse;
import course.CourseModel;
import course.UpdateCourse;
import selects.AddSelect;
import selects.SelectsModel;
import selects.UpdateSelect;
import stu.AddStu;
import stu.UpdateStu;
import stu.UserModel;
public class Main extends JFrame {
public static UserModel userModel;
public static CourseModel coursemodel;
public static SelectsModel selectsmodel;
JTextField exit;
public Main() {
setTitle("学生选课管理系统");
setBounds(300, 100, 1000, 800);
String sql = "select * from stu";
userModel = new UserModel();
userModel.init(sql);
String sql1 = "select * from course";
coursemodel = new CourseModel();
coursemodel.init(sql1);
String sql2 = "SELECT sc.sno,stu.name,sc.cno,course.cname,credit,score FROM sc,stu,course where sc.sno=stu.sno and course.cno=sc.cno";
selectsmodel = new SelectsModel();
selectsmodel.init(sql2);
// 学生表
JTable jTable = new JTable();
jTable.setModel(userModel);
JScrollPane jScrollPane = new JScrollPane();
jScrollPane.setViewportView(jTable);
add(jScrollPane, BorderLayout.CENTER);
// 菜单栏
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
// 学生信息菜单栏
JMenu user = new JMenu(" 学生管理 ");
menuBar.add(user);
JMenuItem addstu = new JMenuItem("增加学生");
JMenuItem updatestu = new JMenuItem("修改学生");
JMenuItem deletestu = new JMenuItem("删除学生");
user.add(addstu);
user.add(updatestu);
user.add(deletestu);
// 课程管理菜单栏
JMenu course = new JMenu(" 课程管理 ");
menuBar.add(course);
JMenuItem addcourse = new JMenuItem("增加课程");
JMenuItem updatecourse = new JMenuItem("修改课程");
JMenuItem deletecourse = new JMenuItem("删除课程");
course.add(addcourse);
course.add(updatecourse);
course.add(deletecourse);
// 选课管理菜单栏
JMenu select = new JMenu(" 选课管理 ");
menuBar.add(select);
JMenuItem addselect = new JMenuItem("添加选课");
JMenuItem updateselect = new JMenuItem("修改选课");
JMenuItem deleteselect = new JMenuItem("删除选课");
select.add(addselect);
select.add(updateselect);
select.add(deleteselect);
// 查询管理菜单栏
JMenu query = new JMenu(" 查询管理 ");
menuBar.add(query);
JMenuItem querystu = new JMenuItem("查询所有学生");
JMenuItem querycourse = new JMenuItem("查询所有课程");
JMenuItem queryselect = new JMenuItem("查询所有选课");
query.add(querystu);
query.add(querycourse);
query.add(queryselect);
// 系统退出
JLabel exit = new JLabel(" 系统退出");
exit.setForeground(Color.red);
exit.setFont(new java.awt.Font("宋体", 1, 15));
menuBar.add(exit);
// 查询区
JPanel jPaneln = new JPanel();
JLabel nameJLabel = new JLabel("学号/课程号:");
JTextField nameField = new JTextField(20);
JButton selectbtn = new JButton("查询");
jPaneln.add(nameJLabel);
jPaneln.add(nameField);
jPaneln.add(selectbtn);
add(jPaneln, BorderLayout.NORTH);
// 查询学号/课程号按钮
selectbtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String stu = nameField.getText();
String sql = "select * from stu where sno='" + stu + "'";
userModel.reload(sql);
String sql1 = "select * from course where cno='" + stu + "'";
coursemodel.reload(sql1);
String sql2 = "SELECT sc.sno,stu.name,sc.cno,course.cname,credit,score FROM sc,stu,course where sc.sno=stu.sno and course.cno=sc.cno and sc.sno='"
+ stu + "'";
selectsmodel.reload(sql2);
}
});
/*
* 学生管理
*/
// 增加学生信息
addstu.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
new AddStu().show();
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
});
// 删除学生信息
deletestu.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
int index = jTable.getSelectedRow();
if (index == -1) {
JOptionPane.showMessageDialog(null, "未选中");
} else {
Object user = userModel.rowData.get(index);
String sno = ((Vector) user).get(0).toString();
try {
DBUtil.initst();
int n = DBUtil.st.executeUpdate("delete from stu where sno='" + sno + "'");
if (n > 0) {
JOptionPane.showMessageDialog(null, "删除成功");
} else {
JOptionPane.showMessageDialog(null, "删除失败");
}
UserModel.reload(null);
DBUtil.closeDB();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
});
// 修改学生信息
updatestu.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
int index = jTable.getSelectedRow();
if (index == -1) {
JOptionPane.showMessageDialog(null, "未选中");
} else {
Object user = userModel.rowData.get(index);
new UpdateStu(user).show();
}
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
});
/*
* 课程管理
*/
// 增加课程信息
addcourse.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
new AddCourse().show();
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
});
// 删除课程信息
deletecourse.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
int index = jTable.getSelectedRow();
if (index == -1) {
JOptionPane.showMessageDialog(null, "未选中");
} else {
Object course = coursemodel.rowData1.get(index);
String cno = ((Vector) course).get(0).toString();
try {
DBUtil.initst();
int n = DBUtil.st.ex
飞翔的佩奇
- 粉丝: 6173
- 资源: 1607
最新资源
- 三菱FX3U 步进电机算FB块 FB块的使用可以使程序模块化简单化,进而提高了程序的稳定性和可移植性 此例中使用FB块,可以实现步进电机的算,已知距离求得脉冲数,已知速度可以求得频率 程序中包含
- 双向隔离DCDC仿真simulink
- 基于PSO粒子群PID控制器参数整定粒子群PID psopid 基于粒子群算法整定PID控制器,实现PID控制器参数的自整定(PSO-PID) matlab编写,源码注释详细具体如图,评价指标详
- 3567954014871001-进程的概念.zip
- 伺服电机、步进电机通用的S曲线及梯形加减速控制源码,十分经典,有中文注释及实现原理说明 系前期从某高手卖家处高价购得(技术源头实为国外专业公司) 本人已经在多个自动化控制系统中采用,为摊低成本故低
- DSP28335的Svpwm处理器在环仿真(matlab simulink)
- cruise模型,增程汽车仿真模型,恒功率控制 关于模型: 1.模型是个base模型,基于cruise simulink联合仿真,主要实现恒功率控制以及电制动优先的能量回收策略,主要供学习使用
- Polarion表结构
- ssm中小型企业财务管理系统+jsp.zip
- ssm珠宝首饰交易平台开发+jsp.zip
- ssm助学贷款+jsp.zip
- ssm职工健康每日申报系统设计+vue.zip
- ssm在线作业管理系统的设计与实现+vue.zip
- ssm中国咖啡文化宣传网站的设计与实现+vue.zip
- FIFO verilogIP 包括深度为1的fifo 包括普通同步FIFO和异步FIFO,均为first word fall through模式,同步fifo三种写法,异步fifo三种写法,可参
- ssm在线医疗服务系统+jsp.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈