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

📄

📁 用java编写的 学生学籍管理系统
💻
📖 第 1 页 / 共 4 页
字号:
   textfield1=new JTextField(20);
   textfield2=new JTextField(20);
   textfield3=new JTextField(20);
   textfield4=new JTextField(20);
   textfield5=new JTextField(20);
   textfield6=new JTextField(20);
   textfield7=new JTextField(20);
   group=new ButtonGroup();
   男=new JRadioButton("男",true);
   女=new JRadioButton("女",false);
   group.add(男);
   group.add(女);
   录入=new JButton("录入");
   重置=new JButton("重置");
   录入.addActionListener(this);
   重置.addActionListener(this);
   Box box1=Box.createHorizontalBox();
   box1.add(new JLabel("学号:",JLabel.CENTER));
   box1.add(textfield1);
   Box box2=Box.createHorizontalBox();
   box2.add(new JLabel("姓名:",JLabel.CENTER));
   box2.add(textfield2);
   Box box3=Box.createHorizontalBox();
   box3.add(new JLabel("性别:",JLabel.CENTER));
   box3.add(男);
   box3.add(女);
   Box box4=Box.createHorizontalBox();
   box4.add(new JLabel("专业:",JLabel.CENTER));
   box4.add(textfield3);
   Box box5=Box.createHorizontalBox();
   box5.add(new JLabel("班级:",JLabel.CENTER));
   box5.add(textfield4);
   Box box6=Box.createHorizontalBox();
   box6.add(new JLabel("出生年月(格式:1984-09):",JLabel.CENTER));
   box6.add(textfield5);
   Box box7=Box.createHorizontalBox();
   box7.add(new JLabel("入学年份(格式:2003-09):",JLabel.CENTER));
   box7.add(textfield6);
   Box box8=Box.createHorizontalBox();
   box8.add(new JLabel("籍贯:",JLabel.CENTER));
   box8.add(textfield7);
   Box boxH=Box.createVerticalBox();
   boxH.add(box1);
   boxH.add(box2);
   boxH.add(box3);
   boxH.add(box4);
   boxH.add(box5);
   boxH.add(box6);
   boxH.add(box7);
   boxH.add(box8);
   boxH.add(Box.createVerticalGlue());
   JPanel pCenter=new JPanel();
   pCenter.add(boxH);
   con=getContentPane();
   con.setLayout(new BorderLayout());
   con.add(pCenter,BorderLayout.CENTER);
   JPanel pSouth=new JPanel();
   pSouth.add(录入);
   pSouth.add(重置);
   con.add(pSouth,BorderLayout.SOUTH);
   setSize(600,600);setVisible(false);
   this.setTitle(s);
   validate();
   addWindowListener(new WindowAdapter()
   {public void WindowClosing(WindowEvent e)
   {setVisible(false);}});

  }
public void actionPerformed(ActionEvent e)
  {
    if(e.getSource()==录入)
      {
        String xuehao="";
        xuehao=textfield1.getText().trim();

         if(xuehao.length()>0)
            {
               try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
	           catch(ClassNotFoundException ee){System.out.println("连接异常");}
               try
	           {
				   int i=0;
				   connect=DriverManager.getConnection("jdbc:odbc:Source");
		           sql=connect.createStatement();
	    	       rs=sql.executeQuery("SELECT*FROM 表1 where 学号="+"'"+xuehao+"'");
	               while(rs.next())
	               {
					   i++;
				   }
                   if(i!=0)
                   {
                       String warning="该生基本信息已存在,请到修改页面修改!";
                       JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
                       connect.close();
                   }
                   else
                   {
                       String m="基本信息将被录入!";
                       int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,
                                                                   JOptionPane.INFORMATION_MESSAGE);
                       if(ok==JOptionPane.YES_OPTION)
                       {
						  xuehao="'"+textfield1.getText().trim()+"'";
                          String xingming="'"+textfield2.getText().trim()+"'";
                          String zhuanye="'"+textfield3.getText().trim()+"'";
                          String banji="'"+textfield4.getText().trim()+"'";
                          String chushengnianyue="'"+textfield5.getText().trim()+"'";
                          String ruxuenianfen="'"+textfield6.getText().trim()+"'";
                          String jiguan="'"+textfield7.getText().trim()+"'";
                          String xingbie=null;
                          if(男.isSelected())
                          {
                              xingbie="'"+男.getText().trim()+"'";
                           }
                          else
                          {
                              xingbie="'"+女.getText().trim()+"'";
                           }

                         String temp="insert into 表1 values ( "+xuehao+","+xingming+","+xingbie+","+chushengnianyue+","+ruxuenianfen+","+jiguan+","+banji+","+zhuanye+")";
                         sql.executeUpdate(temp);
     				     textfield1.setText(null);
                         textfield2.setText(null);
                         textfield3.setText(null);
                         textfield4.setText(null);
                         textfield5.setText(null);
                         textfield6.setText(null);
                         textfield7.setText(null);
                       }
			      }
                  connect.close();
			   }
			   catch(SQLException e1){System.out.println("查询异常");}
		   }

         else
            {
              String warning="必须要输入学号!";
              JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
            }
      }
    if(e.getSource()==重置)
      {
        textfield1.setText(null);
        textfield2.setText(null);
        textfield3.setText(null);
        textfield4.setText(null);
        textfield5.setText(null);
        textfield6.setText(null);
        textfield7.setText(null);

      }
  }
}







class 修改界面 extends JDialog implements ActionListener
{
  JTextField textfield1,textfield2,textfield3,textfield4,textfield5,textfield6,textfield7;
  JRadioButton 男,女;
  ButtonGroup group=null;
  JButton 开始修改,录入修改,重置;
  Connection connect;
  Statement sql;
  ResultSet rs;
  Container con;
  public 修改界面(JFrame f,String s)
  {

   textfield1=new JTextField(20);
   textfield2=new JTextField(20);
   textfield3=new JTextField(20);
   textfield4=new JTextField(20);
   textfield6=new JTextField(20);
   textfield5=new JTextField(20);
   textfield7=new JTextField(20);
   group=new ButtonGroup();
   男=new JRadioButton("男",true);
   女=new JRadioButton("女",false);
   group.add(男);
   group.add(女);
   开始修改=new JButton("开始修改");
   录入修改=new JButton("录入修改");
   录入修改.setEnabled(false);
   重置=new JButton("重置");
   textfield1.addActionListener(this);
   开始修改.addActionListener(this);
   录入修改.addActionListener(this);
   重置.addActionListener(this);
   Box box1=Box.createHorizontalBox();
   box1.add(new JLabel("输入要修改信息的学号:",JLabel.CENTER));
   box1.add(textfield1);
   box1.add(开始修改);
   Box box2=Box.createHorizontalBox();
   box2.add(new JLabel("(新)姓名:",JLabel.CENTER));
   box2.add(textfield2);
   Box box3=Box.createHorizontalBox();
   box3.add(new JLabel("(新)性别:",JLabel.CENTER));
   box3.add(男);
   box3.add(女);
   Box box4=Box.createHorizontalBox();
   box4.add(new JLabel("(新)出生年月(格式:1984-09):",JLabel.CENTER));
   box4.add(textfield3);
   Box box5=Box.createHorizontalBox();
   box5.add(new JLabel("(新)入学年份(格式:2003-09):",JLabel.CENTER));
   box5.add(textfield4);
   Box box6=Box.createHorizontalBox();
   box6.add(new JLabel("(新)籍贯:",JLabel.CENTER));
   box6.add(textfield5);
   Box box7=Box.createHorizontalBox();
   box7.add(new JLabel("(新)班级:",JLabel.CENTER));
   box7.add(textfield6);
   Box box8=Box.createHorizontalBox();
   box8.add(new JLabel("(新)专业:",JLabel.CENTER));
   box8.add(textfield7);
   Box boxH=Box.createVerticalBox();
   boxH.add(box1);
   boxH.add(box2);
   boxH.add(box3);
   boxH.add(box4);
   boxH.add(box5);
   boxH.add(box6);
   boxH.add(box7);
   boxH.add(box8);
   boxH.add(Box.createVerticalGlue());
   con=getContentPane();
   con.setLayout(new BorderLayout());
   JPanel pCenter=new JPanel();
   pCenter.add(boxH);
   con.add(pCenter,BorderLayout.CENTER);
   JPanel pSouth=new JPanel();
   pSouth.add(录入修改);
   pSouth.add(重置);
   con.add(pSouth,BorderLayout.SOUTH);
   setSize(600,600);setVisible(false);
   this.setTitle(s);
   validate();
   addWindowListener(new WindowAdapter()
   {public void WindowClosing(WindowEvent e)
   {setVisible(false);}});

  }
 public void actionPerformed(ActionEvent e)
 {
   if(e.getSource()==开始修改||e.getSource()==textfield1)
      {
		   String xuehao=textfield1.getText().trim();
		   if(xuehao.length()>0)
		      {
				  try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
	              catch(ClassNotFoundException ee){System.out.println("连接异常");}
	              try
	              {
					  int i=0;
			          connect=DriverManager.getConnection("jdbc:odbc:Source");
		              sql=connect.createStatement();
	    	          rs=sql.executeQuery("SELECT*FROM 表1 where 学号="+"'"+xuehao+"'");
     	    	      while(rs.next())
		              {
				         i++;
					     录入修改.setEnabled(true);
			             textfield1.setText(rs.getString("学号"));
			             textfield2.setText(rs.getString("姓名"));
			             if(rs.getString("性别").equals("男"))
			                {
			                   男.setSelected(true);
			                }
			             else
			                {
			                  女.setSelected(true);
			                }
			             textfield3.setText(rs.getString("出生年月"));
			             textfield4.setText(rs.getString("入学年份"));
			             textfield5.setText(rs.getString("籍贯"));
			             textfield6.setText(rs.getString("班级"));
			             textfield7.setText(rs.getString("专业"));

			          }
         	          if(i==0)
			          {
			             录入修改.setEnabled(false);
			             String warning="输入学号不存在,重新输入要修改的学号!";
                         JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
			             textfield1.setText(null);
			             textfield2.setText(null);
			             textfield3.setText(null);
			             textfield4.setText(null);
			             textfield6.setText(null);
			             textfield5.setText(null);
			             textfield7.setText(null);


					 }

		             connect.close();
		            }
		          catch(SQLException e1){System.out.println("查询异常");}
	         }
	         else
		     {
	    		      录入修改.setEnabled(false);
		              String warning="必须要输入学号!";
		    	      JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);
		    	      textfield1.setText(null);
		    	      textfield2.setText(null);
		    	      textfield3.setText(null);
		    	      textfield4.setText(null);
		    	      textfield6.setText(null);
	    	          textfield5.setText(null);
		    		  textfield7.setText(null);
		      }
		  }








    if(e.getSource()==录入修改)
    {

			String question="该生基本信息已存在,您想修改他(她)的基本信息吗?";
			JOptionPane.showMessageDialog(this,question,"警告",JOptionPane.QUESTION_MESSAGE);
            String m="基本信息将被修改!";
		    int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,
			                                                 JOptionPane.INFORMATION_MESSAGE);
			if(ok==JOptionPane.YES_OPTION)
			{

			   try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
	           catch(ClassNotFoundException ee){System.out.println("连接异常");}
               try
               {
				   connect=DriverManager.getConnection("jdbc:odbc:Source");
				   sql=connect.createStatement();
				   String xuehao,xingming,xingbie,banji,chushengnianyue,ruxuenianfen,jiguan,zhuanye;
				   xuehao="'"+textfield1.getText().trim()+"'";
				   xingming="'"+textfield2.getText().trim()+"'";
				   zhuanye="'"+textfield7.getText().trim()+"'";
				    banji="'"+textfield6.getText().trim()+"'";
		            chushengnianyue="'"+textfield3.getText().trim()+"'";
	                ruxuenianfen="'"+textfield4.getText().trim()+"'";
			        jiguan="'"+textfield5.getText().trim()+"'";
				    xingbie=null;
				   if(男.isSelected())
				   {
	                 xingbie="'"+男.getText().trim()+"'";
				    }
				     else
	               {
				        xingbie="'"+女.getText().trim()+"'";
                   }
				   sql.executeUpdate("UPDATE 表1 SET 姓名 ="+xingming+","+"性别="+xingbie+","+"班级="+banji+","+"出生年月="+chushengnianyue+","+"入学年份="+ruxuenianfen+","+"籍贯="+jiguan+","+"专业="+zhuanye+" WHERE 学号 ="+xuehao);

                   connect.close();
			   }
			   catch(SQLException e1){System.out.println("查询异常");}
			 }

             else if(ok==JOptionPane.NO_OPTION)
                   {
                     录入修改.setEnabled(true);
                   }
      }

     if(e.getSource()==重置)
      {
        textfield1.setText(null);
        textfield2.setText(null);
        textfield3.setText(null);
        textfield4.setText(null);
        textfield6.setText(null);
        textfield5.setText(null);
        textfield7.setText(null);
      }
   }
}


⌨️ 快捷键说明

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