package studentmessage;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class IndexInt
{
JFrame inframe;
JPanel panel, panelup, paneldown, panelcenter,panelcard;
JLabel lblCustID,lblxm,lblNumber,lblUserName,lblTel,lblMail,lblAddr,lblyw,lblsx,lblyy,lblzy;
JLabel lblpic;
GridBagLayout g;
GridBagConstraints c;
JTextField txtCustID,txtxm,txtNumber, txtName,txtTel,txtMail,txtAddr,txtyw,txtsx,txtyy,txtzy;
JButton btnQuery, btnInsert, btnDelete, btnUpdate,btnexit;
BorderLayout bl;
FlowLayout fl;
GridLayout gl;
Icon image;
public IndexInt()
{
inframe=new JFrame("学生信息录入");
panel = new JPanel();
panelup = new JPanel();
paneldown = new JPanel();
panelcenter = new JPanel();
panelcard=new JPanel();
lblxm=new JLabel("姓名");
txtxm=new JTextField(15);
lblCustID = new JLabel("学生ID");
txtCustID = new JTextField(15);
lblNumber = new JLabel("学号:");
lblUserName = new JLabel("姓名:");
lblTel=new JLabel("电话号码:");
lblMail=new JLabel("邮箱地址:");
lblAddr=new JLabel("家庭住址:");
lblyw=new JLabel("语文:");
lblsx=new JLabel("数学:");
lblyy=new JLabel("英语:");
lblzy=new JLabel("专业:");
lblpic=new JLabel();
btnQuery = new JButton("查询");
btnInsert = new JButton("增加");
btnDelete = new JButton("删除");
btnUpdate = new JButton("修改");
btnexit=new JButton("退出");
txtNumber = new JTextField(15);
txtName = new JTextField(15);
txtTel=new JTextField(15);
txtMail= new JTextField(15);
txtAddr= new JTextField(15);
txtyw=new JTextField(15);
txtsx=new JTextField(15);
txtyy=new JTextField(15);
txtzy=new JTextField(15);
bl = new BorderLayout();
fl = new FlowLayout(FlowLayout.LEFT);
gl = new GridLayout(1, 4);
g = new GridBagLayout();
c = new GridBagConstraints();
image=new ImageIcon("NO.gif");
lblpic=new JLabel(image);
panelcard.add(lblpic);
panelcenter.setLayout(g);
panel.setLayout(bl);
panelup.setLayout(fl);
paneldown.setLayout(gl);
panelup.add(lblCustID);
panelup.add(txtCustID);
panelup.add(lblxm);
panelup.add(txtxm);
panelup.add(btnQuery);
panel.add(panelup, BorderLayout.NORTH);
paneldown.add(btnInsert);
paneldown.add(btnDelete);
paneldown.add(btnUpdate);
paneldown.add(btnexit);
panel.add(paneldown, BorderLayout.SOUTH);
panel.add(panelcard,BorderLayout.EAST);
panel.add(panelcenter, BorderLayout.WEST);
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy = 5;
g.setConstraints(lblNumber, c);
panelcenter.add(lblNumber);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 5;
g.setConstraints(txtNumber, c);
panelcenter.add(txtNumber);
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy = 6;
g.setConstraints(lblUserName, c);
panelcenter.add(lblUserName);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 6;
g.setConstraints(txtName, c);
panelcenter.add(txtName);
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy = 7;
g.setConstraints(lblTel, c);
panelcenter.add(lblTel);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 7;
g.setConstraints(txtTel, c);
panelcenter.add(txtTel);
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy = 8;
g.setConstraints(lblMail, c);
panelcenter.add(lblMail);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 8;
g.setConstraints(txtMail, c);
panelcenter.add(txtMail);
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy = 9;
g.setConstraints(lblAddr, c);
panelcenter.add(lblAddr);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 9;
g.setConstraints(txtAddr, c);
panelcenter.add(txtAddr);
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy = 10;
g.setConstraints(lblyw, c);
panelcenter.add(lblyw);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 10;
g.setConstraints(txtyw, c);
panelcenter.add(txtyw);
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy = 11;
g.setConstraints(lblsx, c);
panelcenter.add(lblsx);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 11;
g.setConstraints(txtsx, c);
panelcenter.add(txtsx);
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy = 12;
g.setConstraints(lblyy, c);
panelcenter.add(lblyy);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 12;
g.setConstraints(txtyy, c);
panelcenter.add(txtyy);
c.anchor = GridBagConstraints.WEST;
c.gridx = 0;
c.gridy = 13;
g.setConstraints(lblzy, c);
panelcenter.add(lblzy);
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = 13;
g.setConstraints(txtzy, c);
panelcenter.add(txtzy);
inframe.getContentPane().add(panel);
Query q = new Query();
btnQuery.addActionListener(q);
btnInsert.addActionListener(q);
btnDelete.addActionListener(q);
btnUpdate.addActionListener(q);
btnexit.addActionListener(q);
}
class Query implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Object obj = evt.getSource(); //获取引发事件的事件源
if (obj==btnQuery)
{
if(txtCustID.getText().length()<=0 && txtxm.getText().length()<=0 )
{
JOptionPane.showMessageDialog(inframe,"请输入要查询的学号或姓名");
}
else
{
String strCustID = txtCustID.getText().trim();
String strxm = txtxm.getText().trim();
try
{ //加载驱动程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//连接数据库
Connection con = DriverManager.getConnection("jdbc:odbc:SDB");
//执行SQL语句
String sql = "select * from Tabel where 学号=? or 姓名=?";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, strCustID);
stmt.setString(2, strxm);
ResultSet rs = stmt.executeQuery();
if (rs.next())
{
txtNumber.setText(rs.getString(1));
txtName.setText(rs.getString(2));
txtTel.setText(rs.getString(3));
txtMail.setText(rs.getString(4));
txtAddr.setText(rs.getString(5));
txtyw.setText(rs.getString(6));
txtsx.setText(rs.getString(7));
txtyy.setText(rs.getString(8));
txtzy.setText(rs.getString(9));
txtCustID.setText("");
txtxm.setText("");
con.close();
}
else
{
JOptionPane.showMessageDialog(inframe, "没有您查询的学生信息!");
txtCustID.setText("");
}
}
catch (ClassNotFoundException e1)
{
JOptionPane.showMessageDialog(inframe, e1.getMessage());
}
catch (SQLException e2)
{
JOptionPane.showMessageDialog(inframe, e2.getMessage());
}
}
}
if(obj==btnInsert)
{
Add add =new Add();
add.addframe.setSize(200,300);
add.addframe.setVisible(true);
add.addframe.show();
inframe.setVisible(false);
}
if(obj==btnDelete)
{
Delete d=new Delete();
评论0