import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
public class StudentForm extends JFrame implements ActionListener {
private String ss;
//private Vector Vector;
private JLabel welcome = new JLabel("欢迎使用学生管理系统,");
private JLabel userName = new JLabel();
private JLabel name = new JLabel("姓名");
private JLabel sex = new JLabel("性别");
private JLabel birth = new JLabel("出生日期");
private JLabel nation = new JLabel("民族");
private JLabel clas = new JLabel("班级");
private JLabel address = new JLabel("地址");
private JTextField na = new JTextField();
private JTextField se = new JTextField();
private JTextField bi = new JTextField();
private JTextField nat = new JTextField();
private JTextField cl = new JTextField();
private JTextField ad = new JTextField();
private JButton selectClass = new JButton("查询我的班级");
private JButton selectCourse = new JButton("查询我的课程");
private JButton selectTest = new JButton("查询我的考试");
private JTable message = new JTable();
public StudentForm(String s){
setVisible(true);
this.setTitle("学生管理系统");
this.setSize(500, 180);
this.setLocation(500,200);
this.ss = s;
userName.setText(s+"!");
JPanel jp1 = new JPanel(new FlowLayout());
JPanel jp2 = new JPanel(new GridLayout(3,4,10,3));
JPanel jp3 = new JPanel(new FlowLayout());
JPanel jp4 =new JPanel(new FlowLayout());
JPanel j0= new JPanel(new BorderLayout());
jp1.add(welcome);
jp1.add(userName);
jp2.add(name);
jp2.add(na);
jp2.add(sex);
jp2.add(se);
jp2.add(birth);
jp2.add(bi);
jp2.add(nation);
jp2.add(nat);
jp2.add(clas);
jp2.add(cl);
jp2.add(address);
jp2.add(ad);
jp3.add(selectClass);
jp3.add(selectCourse);
jp3.add(selectTest);
message.setCellSelectionEnabled(false);
message.setToolTipText("test tool tip");
message.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
message.setShowHorizontalLines(true);
message.setShowVerticalLines(true);
JScrollPane scroll=new JScrollPane(message);
j0.add(scroll,null);
jp4.add(message);
j0.add(jp1,"North");
j0.add(jp2,"Center");
j0.add(jp3,"South");
j0.add(jp4,"East");
setContentPane(j0);
//布局设计完毕
selectClass.addActionListener(this);
selectCourse.addActionListener(this);
selectTest.addActionListener(this);//按钮添加监听器
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(selectClass)){
try
{
Statement stmt = LoginForm.ct.createStatement();
ResultSet rs = stmt.executeQuery("select 班级编号,班级名,班级人数,所属系别 from "
+ "[StudentManager].[dbo].[班级信息],[StudentManager].[dbo].[学生信息] "
+ "where 学生信息.姓名='"+ss+"'and 学生信息.所属班级=班级信息.班级编号 ");
//ResultSet rst=stmt.executeQuery(sql);
// Vector.removeAllElements();
//message.fireTableStructureChanged();//刷新表格显示结果集中的内容
while(rs.next()){
Vector v=new Vector();
v.addElement(String.valueOf(rs.getString("班级编号")));
v.addElement(String.valueOf(rs.getString("班级名")));
// Vector.addElement(v);
}
//tm.fireTableStructureChanged();
rs.close();
stmt.close();
}
catch(SQLException f) {
System.out.println("SQL异常");
f.printStackTrace();
}
}
}
public static void main (String args[]){
StudentForm s1 = new StudentForm("张苗苗");
s1.setVisible(true);
s1.pack();
}
}