主界面:
/*
* mini 版学生管理系统
* 1. 查询
* 2. 添加
* 3. 删除
* 4. 修改
*/
package model2;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
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;
public class StuManage extends JFrame implements ActionListener{
JPanel jp1, jp2;
JLabel jl1;
JButton jb1, jb2, jb3, jb4;
JTable jt = null;
JScrollPane jsp = null;
JTextField jtf;
JTable jt2 = null;
JScrollPane jsp2 = null;
Connection conn = null;
PreparedStatement ps = null;
StuModel stu;
public static void main(String[] args) {
// TODO Auto-generated method stub
StuManage demo = new StuManage();
}
public StuManage(){
jp1 = new JPanel();
jtf = new JTextField(10);
jb1 = new JButton("查询");
jb1.addActionListener(this);
jl1 = new JLabel("请输入名字");
jp1.add(jl1);
jp1.add(jtf);
jp1.add(jb1);
jp2 = new JPanel();
jb2 = new JButton("添加");
jb2.addActionListener(this);
jb3 = new JButton("修改");
jb3.addActionListener(this);
jb4 = new JButton("删除");
jb4.addActionListener(this);
jp2.add(jb2);
jp2.add(jb3);
jp2.add(jb4);
StuModel stu = new StuModel();
String[] paras = {"1"};
stu.queryStu("select * from stu where 1=?", paras);
jt = new JTable(stu);
jsp = new JScrollPane(jt);
this.add(jsp);
this.add(jp1, "North");
this.add(jp2, "South");
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == jb1){
String name = this.jtf.getText().trim();
String sql = "select * from stu where stuName=?";
String[] paras = {name};
stu = new StuModel();
stu.queryStu(sql, paras);
jt.setModel(stu);
}else if(e.getSource() == jb2){
StuAddDialog sa = new StuAddDialog(this, "添加", true);
stu = new StuModel();
String[] paras = {"1"};
stu.queryStu("select * from stu where 1=?", paras);
jt.setModel(stu);
}else if(e.getSource() == jb3){
int rowNum = this.