import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.sql.*;
//////////////////////////////////////////////
//程序说明:
//您要建立一个数据库STU
//属性为id sex name nation classs birthday
//都为字符型
//数据源名称为sun
//表名:CoolD
////////////////////////////////////////////
public class Student{
public static void main(String []args)
{new Frm_Main();}}
class Frm_Main implements ActionListener //throws IOException
{
public JFrame frame;
public Container c;
public JMenuBar menuBar;
public JMenu mainMenu1;
public JMenu mainMenu2;
public JMenu mainMenu3;
public JMenuItem subMenu1[] = new JMenuItem[5];
public JMenuItem subMenu2[] = new JMenuItem[7];
public JMenuItem subMenu3[] = new JMenuItem[2];
JButton toolBarButton[] = new JButton[8];
public JToolBar toolBar;
//////////////////////////////////////////////
String strTip[] = {"查询您要找的学生记录...","添加学生记录...","删除已有的学生记录","修改学生记录...","使您修改的学生记录生效...","使您添加的学生记录生效...","确认删除当前记录...","退出本系统:)"};
//////////////////////////////////////////////
String id = new String();
String name = new String();
String sex = new String();
String nation = new String();
String classs = new String();
String java = new String();
//////////////////////////////////////////////
Connection con;
ResultSet rs;
Statement st;
///////////////////////////////////////////////
public JLabel idL = new JLabel("学号:");
public JLabel nameL = new JLabel("姓名:");
public JLabel sexL = new JLabel("性别:");
public JLabel nationL = new JLabel("民族:");
public JLabel classsL = new JLabel("班级:");
public JLabel javaL = new JLabel("Java:");
public JTextField idT = new JTextField();
public JTextField nameT = new JTextField();
public JTextField sexT = new JTextField();
public JTextField nationT = new JTextField();
public JTextField classsT = new JTextField();
public JTextField javaT = new JTextField();
//////////////////////////////////////////////
public Frm_Main()
{
/////////////////////////////////////////////////
frame = new JFrame("学生信息管理");
c = frame.getContentPane();
c.setLayout(null);
menuBar = new JMenuBar();
toolBar = new JToolBar();
toolBar.setFloatable(false);
frame.setJMenuBar(menuBar);
frame.setResizable(false);
////////////////////////////////////////////////
mainMenu1 = new JMenu("管理");
String str1[] = {"添加用户","删除用户","查询用户"," ","退出"};
for(int i=0;i<5;i++)
{
if(i==3)
mainMenu1.addSeparator();
else
{
subMenu1[i] = new JMenuItem(str1[i]);
subMenu1[i].addActionListener(this);
mainMenu1.add(subMenu1[i]);
}
}
menuBar.add(mainMenu1);
/////////////////////////////////////////////////
mainMenu2 = new JMenu("维护学生信息");
String str2[] = {"查询记录","添加记录","删除记录","修改记录","提交修改","提交添加","确认删除"};
for(int i=0;i<7;i++)
{
subMenu2[i] = new JMenuItem(str2[i]);
subMenu2[i].addActionListener(this);
mainMenu2.add(subMenu2[i]);
}
menuBar.add(mainMenu2);
/////////////////////////////////////////////////
mainMenu3 = new JMenu("帮助");
String str3[] = {"帮助...","关于..."};
for(int i=0;i<2;i++)
{
subMenu3[i] = new JMenuItem(str3[i]);
subMenu3[i].addActionListener(this);
mainMenu3.add(subMenu3[i]);
}
menuBar.add(mainMenu3);
////////////////////////////////////////////////
String strToolBar[] ={"查询","添加","删除","修改","提交修改","提交添加","确认删除","关于"};
for(int i=0;i<8;i++)
{
toolBarButton[i] = new JButton(strToolBar[i]);
// toolBarButton[i].setToolTipText(strTip[i]);
toolBarButton[i].addActionListener(this);
toolBar.add(toolBarButton[i]);
}
toolBar.setLocation(0,0);
toolBar.setSize(400,30);
c.add(toolBar);
////////////////////////////////////////////////
idL.setLocation(35,40);
idL.setSize(40,20);
//idL.setFont(new Font("宋体",Font.BOLD,12));
c.add(idL);
idT.setLocation(90,40);
idT.setSize(200,20);
//idT.setEnabled(false);
c.add(idT);
nameL.setLocation(35,70);
nameL.setSize(40,20);
c.add(nameL);
nameT.setLocation(90,70);
nameT.setSize(200,20);
c.add(nameT);
sexL.setLocation(35,100);
sexL.setSize(40,20);
c.add(sexL);
sexT.setLocation(90,100);
sexT.setSize(200,20);
c.add(sexT);
nationL.setLocation(35,130);
nationL.setSize(40,20);
c.add(nationL);
nationT.setLocation(90,130);
nationT.setSize(200,20);
c.add(nationT);
classsL.setLocation(35,160);
classsL.setSize(40,20);
c.add(classsL);
classsT.setLocation(90,160);
classsT.setSize(200,20);
c.add(classsT);
javaL.setLocation(35,190);
javaL.setSize(40,20);
c.add(javaL);
javaT.setLocation(90,190);
javaT.setSize(200,20);
c.add(javaT);
/////////////////////////////////////////////////
////////////////////////////////////////////////
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setLocation(200,200);
frame.setVisible(true);
conDB();
}
//以上是设置数据库面版、框架
//以下是连接数据库
public void conDB()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println(""+e);
//JOptionPane.showMessageDialog(null,"您数据库加载失败了,呵呵!");
}
try
{
con = DriverManager.getConnection("jdbc:odbc:sun","","");
st = con.createStatement();
}
catch(SQLException e)
{
System.out.println(e);
//JOptionPane.showMessageDialog(null,"数据库连接失败了,呵呵!");
}
}
//以下是关闭数据库
public void closeDB()
{
try
{
st.close();
con.close();
}
catch(SQLException e )
{
JOptionPane.showMessageDialog(null,"数据库关闭失败了,呵呵!");
}
}
//以下是针对数据库的各种操作
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==subMenu1[0] || e.getSource()==subMenu1[1] || e.getSource()==subMenu1[2] )
JOptionPane.showMessageDialog(null,"暂不实现!!");
/////////////////////////////////////////////////////////////////////////////////////
//查找功能的实现
if(e.getSource()==subMenu2[0]||e.getSource()==toolBarButton[0])
{
String idid = JOptionPane.showInputDialog("请输入要查找的学生学号");
if(idid.trim()!="")
{
String strSQL = "select * from CoolD where id ='" + idid + "'";
try
{
//rs = st.executeQuery("select * from CoolD where id ='2004010123'");
rs = st.executeQuery(strSQL);
int count = 0;
while(