⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 20041158133492905.java

📁 用JAVA做的一个学生管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.sql.*;


//主函数、主要类
 class JCTX{
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 birthday = new String();
    String department = 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 departmentL = new JLabel("专业:");
    public JLabel birthdayL = new JLabel("生日:");
    public JTextField idT = new JTextField();
    public JTextField nameT = new JTextField();
    public JTextField sexT = new JTextField();
    public JTextField nationT = new JTextField();
    public JTextField departmentT = new JTextField();
    public JTextField birthdayT = new JTextField();
//////////////////////////////////////////////

//////////////////////////////////////////////
    public Frm_Main()
    {
/////////////////////////////////////////////////
        frame = new JFrame("简易学生信息管理子系统1.0版");
        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);

         departmentL.setLocation(35,160);
         departmentL.setSize(40,20);
         c.add(departmentL);

         departmentT.setLocation(90,160);
         departmentT.setSize(200,20);
         c.add(departmentT);

         birthdayL.setLocation(35,190);
         birthdayL.setSize(40,20);
         c.add(birthdayL);

         birthdayT.setLocation(90,190);
         birthdayT.setSize(200,20);
         c.add(birthdayT);
/////////////////////////////////////////////////

         JLabel information = new JLabel("某某");
         information.setFont(new Font("宋体",Font.BOLD,35));
         information.setSize(380,110);
         information.setLocation(10,210);
         c.add(information);
////////////////////////////////////////////////
         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)
       {
          JOptionPane.showMessageDialog(null,"您数据库加载失败了,呵呵!");
       }
      try
       {
          con = DriverManager.getConnection("jdbc:odbc:jctx","sa","");
          st = con.createStatement();
        }
       catch(SQLException 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()==subMenu3[1] ||e.getSource()==toolBarButton[7])
              JOptionPane.showMessageDialog(null,"本软件由华瑞工作室编写");
///////////////////////////////////////////////////////////////////////////////////
         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 Coolboy where id ='" + idid + "'";
                  try

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -