视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
(完整版)学生学籍管理系统(含java源代码)
2025-10-05 01:32:59 责编:小OO
文档
学生学籍管理详细设计

           学号:____________

           姓名:____________

           班级:____________

一、设计题目:

学生学籍管理

二:设计内容:

   设计GUI学生学籍管理界面,用户可以加入学生信息,并对基本信息进行修改,添加,查询,删除。

三:设计要求:

   进行简单的学生信息管理。

四:总体设计

   (1)登陆界面的设计

  (2)主窗体的设计

  (3)添加学生信息窗体

  (4)查询学生信息窗体

  (5)修改学生信息窗体

  (6)删除学生信息窗体

  (7)事件响应的处理

五:具体设计

(1)程序结构的说明:

A.入口程序:student.java;

B.登陆界面程序:mainframe.java;

C.主窗体程序:interfac.java;

D.添加信息窗口程序:tj.java;

E.修改信息窗口程序:xg.java;

F.查询信息窗口程序:cx.java;

G.删除信息窗口程序:sc.java;

H.程序数据连接:DatabaseConn.java;

(2)程序代码及分析说明

A.程序源代码(已提交)

B.Student.java是程序的入口。使登录窗口位于窗口中间,并且不可改变窗口大小。

C.mainframe.java是程序的登陆窗体。输入用户名和密码(用户名和密码在数据库的password表中)点击“进入系统”,然后登陆界面消失;出现要操作的界面(屏幕左上角)。

D.tj.java是添加信息界面。添加基本信息后,点击“添加信息”按钮,将信息加入xinxi表中。

E.xg.java是修改信息界面。输入要修改的学号或姓名(两者数其一或全部输入),并输入所有信息,点击“修改信息”按钮(如果数据库中不存在此学号,则弹出对话框“无此学生信息”),若有则修改。

F.sc.java是删除信息界面。输入要删除的学生的学号,点击“删除信息”按钮,弹出确认删除对话框,即可删除该生信息。

G.cx.java是查询信息界面。输入要查询的学生学号,点击“信息查询”按钮,在相应的文本区里显示查询的信息。

H:源代码

//student.java:程序的入口。初始化界面,使主界面位于屏幕中间,且用户不能改变大小

//功能:完成程序的执行顺序

import javax.swing.UIManager;

import java.awt.*;

import java.sql.*;

//import screen

public class student

{

    boolean packFrame=false;

    //JFrame frame=new JFrame();

    public student()

    {

        mainframe frame=new mainframe();

        if(packFrame)

        {

            frame.pack();

            }

            else

            { 

                frame.validate();

                }

            Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();

            Dimension frameSize=frame.getSize();

         if(frameSize.height>screenSize.height)

            {

                frameSize.height=screenSize.height;

                }

             if(frameSize.width>screenSize.width)

                {

                    frameSize.width=screenSize.width;

                    }

                    frame.setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2);

                    frame.setVisible(true);

        }

        public static void main(String[] args)

        {

            try{

                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

                }

                catch(Exception e)

                {

                    e.printStackTrace();

                }

                new student();

            }

    }

//数据库连接

//package sql.database;

import java.sql.*;

public class DatabaseConn

{

    private static String user="";

    private static String password="";

    private Connection conn=null;

    private Statement stmt=null;

    private ResultSet rs=null;

    static

     {

         try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动

             }

             catch(ClassNotFoundException e){}

        }

        //创建数据库连接对象

        public Connection getConnection()

        {

            try{

                conn=DriverManager.getConnection("jdbc:odbc:stu",user,password);

                return conn;

                

                }catch(SQLException e)

                {

                    return null;

                }

            }

            public Statement createStat()

            {

                try{

                    conn=getConnection();

                    stmt=conn.createStatement();

                    return stmt;

                    }catch(SQLException e)

                    {return null;}

                }

                public ResultSet getRs(String sql)

                {

                    

        try{

            conn=getConnection();//...

            stmt=createStat();

            rs=stmt.executeQuery(sql);

            return rs;

        }catch(SQLException e)

        { 

            return null;

            }

                    

                    }

                    public void close()

                    {

                         try{

          if(rs!=null)

            rs.close();

          if(stmt!=null)

            stmt.close();

          if(conn!=null)

            conn.close();

        }catch(SQLException ex)

        {

            ex.printStackTrace();

        }

                        }

                    

    }

//mainframe.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.sql.*;

public class mainframe extends JFrame   implements ActionListener

{

    

    static mainframe s;

    static JPanel pan=new JPanel();

    static JLabel label1 = new JLabel("用  户");

  static JLabel label2 = new JLabel("密  码");

  static  JTextField textField1 = new JTextField();

  static  JPasswordField password = new JPasswordField();

  static JButton button1 = new JButton("进入系统");   

   

  static JRadioButton radioButton1=new JRadioButton("管理员",true);//“管理员”初始状态被选中

  static JRadioButton radioButton2=new JRadioButton("学生");

  static JRadioButton radioButton3=new JRadioButton("教师");

  ButtonGroup buttonGroup=new ButtonGroup();

  public mainframe()

    {

    

        label.setSize(400,400);

        pan.add(label);

        pan.setLayout(null);

        pan.setSize(400,400);    

        this.setTitle("学籍管理系统");

        this.setSize(400,400);

        this.setLayout(null);

        label1.setBounds(100,25,49,20);    

        textField1.setBounds(155,24,120,20);

        label2.setBounds(100,62,49,20);

        password.setBounds(155,61,120,20);

        button1.setBounds(150,200,101,22);

                radioButton1.setBounds(105,120,80,20);

                radioButton2.setBounds(180,120,60,20);

        radioButton3.setBounds(240,120,60,20);

        button1.addActionListener(this);    

            

        buttonGroup.add(radioButton1);

                buttonGroup.add(radioButton2);

        buttonGroup.add(radioButton3);

        this.add(radioButton1);

        this.add(radioButton2);

        this.add(radioButton3);

        this.add(label1);

        this.add(label2);

        this.add(textField1);

        this.add(password);

        this.add(button1);

        this.add(pan);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.setVisible(true);

        

        

    }

      public static void main(String[] args)

      {

          new mainframe();

      }

      

      

      

     public void actionPerformed(ActionEvent e)

      {        

      

              if(radioButton1.isSelected())//管理员

              {

                  if(textField1.getText().equals("syc") && password.getText().equals("123")){

                interfac b=new interfac();

                this.dispose();

                //JOptionPane.showMessageDialog(null,"登陆成功");

            }else if("".equals(textField1.getText()) || "".equals(password.getText()) ){

                JOptionPane.showMessageDialog(null,"用户名或密码不能为空");

            }else{

                JOptionPane.showMessageDialog(null,"用户名或密码输入有误");

            }

            

        }

if(radioButton2.isSelected())//学生

    {

    try{

    

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            }

    catch (ClassNotFoundException ce)

        {

        JOptionPane.showMessageDialog(s,ce.getMessage());

            }

    try

    {

        Connection con = DriverManager.getConnection("jdbc:odbc:stu

        Statement stmt = con.createStatement();

    ResultSet rs = stmt.executeQuery("select * from password where 用户名 = '"+textField1.getText()+"' and 密码 = '"+password.getText()+"'");

                

                if(textField1.getText().equals("")||password.getText().equals(""))

                {

                    JOptionPane.showMessageDialog(this,"用户名或密码不可为空!");

                }

                else if(rs.next())

               

               {   new interfac();} 

                         

                         else 

                {JOptionPane.showMessageDialog(this,"您的输入有误");}

                

                //stmt.close();

            }

       

    catch (SQLException se)

    {

        JOptionPane.showMessageDialog(s,se.getMessage());

            }

        }

    }

}

//interface.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class interfac extends JFrame implements ActionListener

{

    static JMenuBar jMenuBar = new JMenuBar();//菜单条

  static JMenu jMenuFile = new JMenu("文件");//菜单项

  static JMenu jMenuExit = new JMenu("退出");

  static JMenuItem jMenuItem1 = new JMenuItem("添加信息");//菜单子项

  static JMenuItem jMenuItem2 = new JMenuItem("修改信息");

  static  JMenuItem jMenuItem3 = new JMenuItem("信息查询");

  static JMenuItem jMenuItem4 = new JMenuItem("删除信息");

  static  JLabel label3 = new JLabel("请选择操作项");

  static  JLabel label4 = new JLabel("学籍管理系统");

  static  JButton button2 = new JButton("添加信息");

  static  JButton button3 = new JButton("修改信息");

  static  JButton button4 = new JButton("信息查询");

  static  JButton button5 = new JButton("删除信息");

  

    public interfac()

    {

        this.setTitle("学籍管理系统");

        this.setLayout(null);

        this.setSize(400,400);

        label3.setBounds(158,92,98,33);

        label3.setFont(new Font("Dialog",Font.PLAIN,15));

        label4.setFont(new Font("Dialog",Font.BOLD,20));

        label4.setBounds(157,37,280,40);

        button2.setBounds(74,136,97,33);

        button3.setBounds(226,136,97,33);

        button4.setBounds(74,185,97,33);    

        button5.setBounds(226,185,97,33);

        this.add(button2);

        this.add(button3);

        this.add(button4);

        this.add(button5);

        this.add(label3);

        this.add(label4);

        setJMenuBar(jMenuBar);

        jMenuFile.add(jMenuItem1);//”文件“菜单项中加入子菜单

      jMenuFile.add(jMenuItem2);

      jMenuFile.add(jMenuItem3);

      jMenuFile.add(jMenuItem4);

      jMenuBar.add(jMenuFile);//将菜单项加入菜单条

    jMenuBar.add(jMenuExit);

    button2.addActionListener(this);//本窗口向按钮事件源注册

    button3.addActionListener(this);

    button4.addActionListener(this);

    button5.addActionListener(this);

    jMenuItem1.addActionListener(this);//本窗口菜单子项注册

    jMenuItem2.addActionListener(this);

    jMenuItem3.addActionListener(this);

    jMenuItem4.addActionListener(this);  

    jMenuExit.addActionListener(this);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.setVisible(true);

    }

        public static void main(String[] args)

        {

            interfac a=new interfac();

            }

  

    public void actionPerformed(ActionEvent e) //按钮事件的处理

    {

        if(e.getSource()==jMenuExit)

        {

            System.exit(0);

            }

       else if(e.getSource()==jMenuItem1||e.getSource()==button2)

        { 

            try{              

            tj a=new tj();

        }

        catch(Exception ee)   {}     

      }

        else if(e.getSource()==jMenuItem2||e.getSource()==button3)

               {    

                   try{               

                 xg a=new xg();    

               }catch(Exception ed)     {}      

               }

               else if(e.getSource()==jMenuItem3||e.getSource()==button4)

                    {

                        try{

                    cx a=new cx();}

                    catch(Exception ec){}

                       }

                       else if(e.getSource()==jMenuItem4||e.getSource()==button5)

                           { 

                               try{

                             sc a=new sc();

                           }catch(Exception es){}

                        }

                     

       }

  }

               

//tj.java  添加界面

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class tj extends JFrame implements ActionListener 

{

    static tj s;

  static JLabel label1 = new JLabel("学号:");

  static  JTextField textField1 = new JTextField("");

  static  JLabel label2 = new JLabel("姓名:");

  static JTextField textField2 = new JTextField("");

  static  JLabel label3 = new JLabel("性别:");

  static JTextField textField7=new JTextField("");

  static  JLabel label4 = new JLabel("出生日期:");

  static   JTextField textField3 = new JTextField("");

  static  JLabel label5 = new JLabel("政治面貌:");

  static JTextField textField8=new JTextField("");

  static   JLabel label6 = new JLabel("籍贯");

  static  JTextField textField4 = new JTextField("");

  static  JLabel label7 = new JLabel("系别:");

  static JTextField textField9 = new JTextField("");

  static   JLabel label8 = new JLabel("专业:");

  static  JTextField textField5 = new JTextField("");

  static  JButton button1 = new JButton("增加");

  

  public tj()

  {

      this.setTitle("增加学生信息");

      this.setLayout(null);

    this.setSize(400,400);

    label1.setBounds(30, 11, 51, 33);

    textField1.setBounds(86, 16, 74, 22);

    label2.setBounds(162, 11, 51, 33);

    textField2.setBounds(192, 16, 44, 22);

    label3.setBounds(241, 11, 70, 33);

    textField7.setBounds(275, 15, 50, 25);

    label4.setBounds(31, 53, 55, 33);

    textField3.setBounds(86, 58, 74, 22);

    label5.setBounds(241, 53, 70, 33);

    textField8.setBounds(296, 57, 72, 25);

    label6.setBounds(163, 53, 26, 33);

    textField4.setBounds(191, 58, 44, 22);

    label7.setBounds(30, 94, 50, 33);

    textField9.setBounds(86,94,74,22);

    label8.setBounds(163, 94, 51, 33);

    textField5.setBounds(190, 99, 178, 22);

    button1.setBounds(25,241,80,33);

    button1.addActionListener(this);

    

    this.add(label1);

    this.add(label2);

    this.add(label3);

    this.add(label4);

    this.add(label5);

    this.add(label6);

    this.add(label7);

    this.add(label8);

    this.add(textField1);

    this.add(textField2);

    this.add(textField3);

    this.add(textField4);

    this.add(textField5);

    this.add(textField7);

    this.add(textField8);

    this.add(textField9);

    this.add(button1);

    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

   this.setVisible(true);

  }

public static void main(String[] args) throws Exception

  {

  tj a=    new tj();

  a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     

    

  }

   public void actionPerformed(ActionEvent e)//事件处理程序

   {

    

   if (e.getSource() == button1) 

    {

        try{

    

                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                    }

            catch (ClassNotFoundException ce)

                {

                    JOptionPane.showMessageDialog(s,ce.getMessage());

                }

            try

            {

            Connection con = DriverManager.getConnection("jdbc:odbc:stu

");

            Statement stmt = con.createStatement();

     ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText

()+"'");

         if(rs.next())

         {

             JOptionPane.showMessageDialog(null,"此学号已经被注册");

             }

             else

             {

                 stmt.execute("insert into xinxi (学号,姓名,性别,出生日期,政治面貌,

籍贯,系别,专业) values ('"+

                        textField1.getText()+"','"+textField2.getText()

+"','"+textField7.getText()+"','"+

                        textField3.getText()+"','"+textField8.getText()

+"','"+textField4.getText()+"','"+                      

                       textField9.getText()+"','"+textField5.getText()+"')");

                JOptionPane.showMessageDialog(null,"添加信息成功");

           }          

  }

  catch (SQLException se)

            {

                JOptionPane.showMessageDialog(s,se.getMessage());

            }

    }

   }

 }

  

//xg.java  修改界面

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class xg extends JFrame implements ActionListener 

{

    static xg s;

  static JLabel label1 = new JLabel("学号:");

  static  JTextField textField1 = new JTextField("");

  static  JLabel label2 = new JLabel("姓名:");

  static JTextField textField2 = new JTextField("");

  static  JLabel label3 = new JLabel("性别:");

  static JTextField textField7=new JTextField("");

  static  JLabel label4 = new JLabel("出生日期:");

  static   JTextField textField3 = new JTextField("");

  static  JLabel label5 = new JLabel("政治面貌:");

  static JTextField textField8=new JTextField("");

  static   JLabel label6 = new JLabel("籍贯");

  static  JTextField textField4 = new JTextField("");

  static  JLabel label7 = new JLabel("系别:");

  static JTextField textField9 = new JTextField("");

  static   JLabel label8 = new JLabel("专业:");

  static  JTextField textField5 = new JTextField("");

  static JButton button2=new JButton("修改");

  public xg()

  {

      this.setTitle("修改学生信息");

      this.setLayout(null);

    this.setSize(400,400);

    label1.setBounds(30, 11, 51, 33);

    textField1.setBounds(86, 16, 74, 22);

    label2.setBounds(162, 11, 51, 33);

    textField2.setBounds(192, 16, 44, 22);

    label3.setBounds(241, 11, 70, 33);

    textField7.setBounds(275, 15, 50, 25);

    label4.setBounds(31, 53, 55, 33);

    textField3.setBounds(86, 58, 74, 22);

    label5.setBounds(241, 53, 70, 33);

    textField8.setBounds(296, 57, 72, 25);

    label6.setBounds(163, 53, 26, 33);

    textField4.setBounds(191, 58, 44, 22);

    label7.setBounds(30, 94, 50, 33);

    textField9.setBounds(86,94,74,22);

    label8.setBounds(163, 94, 51, 33);

    textField5.setBounds(190, 99, 178, 22);

    button2.setBounds(115,241,80,33);

    button2.addActionListener(this);

    this.add(label1);

    this.add(label2);

    this.add(label3);

    this.add(label4);

    this.add(label5);

    this.add(label6);

    this.add(label7);

    this.add(label8);

    this.add(textField1);

    this.add(textField2);

    this.add(textField3);

    this.add(textField4);

    this.add(textField5);

    this.add(textField7);

    this.add(textField8);

    this.add(textField9);

    this.add(button2);

    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

   this.setVisible(true);

  }

public static void main(String[] args) throws Exception

  {

      xg a=new xg();

    a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

  }

  public void actionPerformed(ActionEvent e)//事件处理程序

   {

    if(e.getSource()==button2)

    {

            try{

    

                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                    }

            catch (ClassNotFoundException ce)

                {

                    JOptionPane.showMessageDialog(s,ce.getMessage());

                }

            try

            {

            Connection con = DriverManager.getConnection

("jdbc:odbc:stu

            Statement stmt = con.createStatement();

     ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText

()+"'");

                if(textField1.getText().trim().equals(""))

                {

                    JOptionPane.showMessageDialog(this,"学号不可为空!");

                }

               

                else if(rs.next())

               {

                   String updateSql="update xinxi set 学号='"+textField1.getText()+"', 姓名

='"+

                                    textField2.getText()+"',性别='"+textField7.getText()+"',出

生日期='"+

                                    textField3.getText()+"',政治面貌='"+textField8.getText()

+"',籍贯='"+

                                    textField4.getText()+"',系别='"+textField9.getText()+"',专

业='"+

                                    textField5.getText()+ "'";

                                    try{

                                        stmt.executeQuery(updateSql);}

                                        catch(SQLException se)

                                        {

                                            JOptionPane.showMessageDialog(null,"修改成

功");

                                            }

                                        

                   

                   }

      }

          catch(SQLException se)

        {

           JOptionPane.showMessageDialog(s,se.getMessage());

          }

    }

  }

}

  

//sc.java  删除界面

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class sc extends JFrame implements ActionListener 

{

    static sc s;

  static JLabel label1 = new JLabel("学号:");

  static  JTextField textField1 = new JTextField("");

  static  JLabel label2 = new JLabel("姓名:");

  static JTextField textField2 = new JTextField("");

  static  JLabel label3 = new JLabel("性别:");

  static JTextField textField7=new JTextField("");

  static  JLabel label4 = new JLabel("出生日期:");

  static   JTextField textField3 = new JTextField("");

  static  JLabel label5 = new JLabel("政治面貌:");

  static JTextField textField8=new JTextField("");

  static   JLabel label6 = new JLabel("籍贯");

  static  JTextField textField4 = new JTextField("");

  static  JLabel label7 = new JLabel("系别:");

  static JTextField textField9 = new JTextField("");

  static   JLabel label8 = new JLabel("专业:");

  static  JTextField textField5 = new JTextField("");

  static JButton button4=new JButton("删除");

  public sc() throws Exception

  {

      this.setTitle("删除学生信息");

      this.setLayout(null);

    this.setSize(400,400);

    label1.setBounds(30, 11, 51, 33);

    textField1.setBounds(86, 16, 74, 22);

    label2.setBounds(162, 11, 51, 33);

    textField2.setBounds(192, 16, 44, 22);

    label3.setBounds(241, 11, 70, 33);

    textField7.setBounds(275, 15, 50, 25);

    label4.setBounds(31, 53, 55, 33);

    textField3.setBounds(86, 58, 74, 22);

    label5.setBounds(241, 53, 70, 33);

    textField8.setBounds(296, 57, 72, 25);

    label6.setBounds(163, 53, 26, 33);

    textField4.setBounds(191, 58, 44, 22);

    label7.setBounds(30, 94, 50, 33);

    textField9.setBounds(86,94,74,22);

    label8.setBounds(163, 94, 51, 33);

    textField5.setBounds(190, 99, 178, 22);

    button4.setBounds(295,241,80,33);

    button4.addActionListener(this);

    this.add(label1);

    this.add(label2);

    this.add(label3);

    this.add(label4);

    this.add(label5);

    this.add(label6);

    this.add(label7);

    this.add(label8);

    this.add(textField1);

    this.add(textField2);

    this.add(textField3);

    this.add(textField4);

    this.add(textField5);

    this.add(textField7);

    this.add(textField8);

    this.add(textField9);

    this.add(button4);

    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

   this.setVisible(true);

  

  }

public static void main(String[] args) throws Exception

  {

  sc a=    new sc();

   a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  

  }

  public void actionPerformed(ActionEvent e)//sc

  {

      if (e.getSource() == button4) 

    {

        try{

    

                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                    }

            catch (ClassNotFoundException ce)

                {

                    JOptionPane.showMessageDialog(s,ce.getMessage());

                }

                try

                {

                    Connection con = DriverManager.getConnection("jdbc:odbc:stu

                Statement stmt = con.createStatement();

          ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText()+"'");

          if(textField1.getText().trim().equals(""))

                {

                    JOptionPane.showMessageDialog(this,"学号不可为空!");

                }

               

                else if(rs.next())

                {

                    JOptionPane.showConfirmDialog(null,"确定要删除该信息嘛?\\n删除的信息将不能恢复,继续?

                        stmt.execute("delete  from xinxi where  学号='"+textField1.getText()+"'");

                        JOptionPane.showMessageDialog(null,"删除信息成功!");

                        this.dispose();                   

                    }

                    else JOptionPane.showMessageDialog(null,"无此学号对应信息

        }          

             catch(Exception ed)

                {

                    JOptionPane.showMessageDialog(s,ed.getMessage());

                }

                    

    }

      }

  }

//cx.java 查询界面

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class cx extends JFrame implements ActionListener 

{

    static cx s;

  static JLabel label1 = new JLabel("学号:");

  static  JTextField textField1 = new JTextField("");

  static  JLabel label2 = new JLabel("姓名:");

  static JTextField textField2 = new JTextField("");

  static  JLabel label3 = new JLabel("性别:");

  static JTextField textField7=new JTextField("");

  static  JLabel label4 = new JLabel("出生日期:");

  static   JTextField textField3 = new JTextField("");

  static  JLabel label5 = new JLabel("政治面貌:");

  static JTextField textField8=new JTextField("");

  static   JLabel label6 = new JLabel("籍贯");

  static  JTextField textField4 = new JTextField("");

  static  JLabel label7 = new JLabel("系别:");

  static JTextField textField9 = new JTextField("");

  static   JLabel label8 = new JLabel("专业:");

  static  JTextField textField5 = new JTextField("");

  static JButton button3=new JButton("查询"); 

  public cx() throws Exception

  {

      this.setTitle("查询学生信息");

      this.setLayout(null);

    this.setSize(400,400);

    label1.setBounds(30, 11, 51, 33);

    textField1.setBounds(86, 16, 74, 22);

    label2.setBounds(162, 11, 51, 33);

    textField2.setBounds(192, 16, 44, 22);

    label3.setBounds(241, 11, 70, 33);

    textField7.setBounds(275, 15, 50, 25);

    label4.setBounds(31, 53, 55, 33);

    textField3.setBounds(86, 58, 74, 22);

    label5.setBounds(241, 53, 70, 33);

    textField8.setBounds(296, 57, 72, 25);

    label6.setBounds(163, 53, 26, 33);

    textField4.setBounds(191, 58, 44, 22);

    label7.setBounds(30, 94, 50, 33);

    textField9.setBounds(86,94,74,22);

    label8.setBounds(163, 94, 51, 33);

    textField5.setBounds(190, 99, 178, 22);

    button3.setBounds(205,241,80,33);

    button3.addActionListener(this);

    this.add(label1);

    this.add(label2);

    this.add(label3);

    this.add(label4);

    this.add(label5);

    this.add(label6);

    this.add(label7);

    this.add(label8);

    this.add(textField1);

    this.add(textField2);

    this.add(textField3);

    this.add(textField4);

    this.add(textField5);

    this.add(textField7);

    this.add(textField8);

    this.add(textField9);

    this.add(button3);

    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

   this.setVisible(true);

 

  }

public static void main(String[] args) throws Exception

  {

      cx a=new cx();

      a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

  }

  public void actionPerformed(ActionEvent e)

{

    if(e.getSource()==button3)

    {

            try{

    

                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                    }

            catch (ClassNotFoundException ce)

                {

                    JOptionPane.showMessageDialog(s,ce.getMessage());

                }

            try

            {

            Connection con = DriverManager.getConnection("jdbc:odbc:stu

            Statement stmt = con.createStatement();

     ResultSet rs=stmt.executeQuery("select * from xinxi where 学号='"+textField1.getText()+"'");

                if(textField1.getText().trim().equals(""))

                {

                    JOptionPane.showMessageDialog(this,"学号不可为空!");

                }

               

                else if(rs.next())

                    {

                textField2.setText(rs.getString("姓名"));

                textField7.setText(rs.getString("性别"));

                textField3.setText(rs.getString("出生日期"));

                textField8.setText(rs.getString("政治面貌"));

                textField4.setText(rs.getString("籍贯"));

                textField9.setText(rs.getString("系别"));

                textField5.setText(rs.getString("专业")); 

                

                } 

         else

                {JOptionPane.showMessageDialog(this,"无此记录");}

                

         }       

       

                catch (SQLException se)

            {

                JOptionPane.showMessageDialog(s,se.getMessage());

            }

        }

    }

}

I. 运行说明

  在DOS窗口输入javac student.java

java student运行程序。(运行时程序的文件一个都不能少,并且在同一文件夹中)

程序效果显示图:

如下图,运行程序:

(3)用户名“syc”,密码“123”(选“管理员”)进入系统。

(4)登陆成功后选择操作项(“文件”下的子菜单也可点击使用):

(5)点击操作项,如“添加信息”,然后点击“增加”按钮

如果此学号已存在,则弹出对话框

若不存在,则弹出

(6)信息查询,修改信息,删除信息的操作与添加信息的一样(只是弹出的对话框信息不同)。下载本文

显示全文
专题