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

📄 student.java

📁 student information management system.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		}
		//------------------------------------------------------------------- Ending with  showStudName() -------	
		//=============================================================== Starting with deleteRecord()  ========	
				
		void deleteRecord(int nsel) //Deleting the record for the selected student name
		{		 	
			  try
			  {					  					
					Class.forName(driver);					
			   		Connection con=DriverManager.getConnection(url);
			   		Statement st = con.createStatement();	
			   		System.out.println("Delete name is :=="+nsel);
					query6 = "DELETE FROM student_details WHERE registration_no="+nsel;
					st.executeUpdate(query6);					
					con.close();			
					mcb_course.setSelectedIndex(0);		 
					mcb_year.setSelectedIndex(0);			 
					tmname.setText(" ");		
					tmdob.setText(" ");			
					tmpreaddress.setText(" ");			
					tmpermaaddress.setText(" ");	
					tmfathername.setText(" ");			
					tmphone.setText(" ");
					mdmc.setSelected(false);			
					mdegree.setSelected(false);			
					mncc.setSelected(false);		
					mcharcerti.setSelected(false);		
					m_male.doClick();						
			  }
			  catch(SQLException ex)
			   {
			    System.out.println("Unable to access the database");
			   }
			  catch(ClassNotFoundException ex)
			   {
			    System.out.println("Class not found");
			   }
			  catch(Exception ex)
			  {
               System.out.println("Exception raised is:"+ex);
			  }
	}	
		//------------------------------------------------------------------- Ending with  deleteRecord() -------	
		//=============================================================== Starting with updateRecord()  ========	

		void updateRecord(int std_id,String str_name) //Update Database when modified
		{
		 	  try
			  {
			  		query7 = "UPDATE student_details SET name='"+tmname.getText()+"', preaddress='"+tmpreaddress.getText()+"', permaaddress='"+tmpermaaddress.getText()+"', fathername='"+tmfathername.getText()+"', dateofbirth='"+tmdob.getText()+"', fatheroccupation='"+foccupation+"', phone='"+tmphone.getText()+"', gender='"+gender+"', year='"+year+"', course='"+course+"', dmc="+dmcsel+", degree="+degreesel+", charcerti="+charcfsel+", ncccerti="+ncccfsel+" WHERE registration_no="+std_id; 
					Class.forName(driver);
			   		Connection con=DriverManager.getConnection(url);
			   		Statement st = con.createStatement();
					System.out.println(query7);
			   		int ret=st.executeUpdate(query7);	
			   		System.out.println("Output is "+ret);
		   			con.close();
		   			System.out.println("Called After"+str_name);
		   			message_dialog = " "+tmname.getText().toUpperCase()+" Record is Updated ";
					type_dialog = JOptionPane.INFORMATION_MESSAGE;
					JOptionPane.showMessageDialog((Component) null, message_dialog, modify_dialog, type_dialog);
			  }
			  catch(SQLException ex)
			   {
			    System.out.println("Unable to access the database");
			   }
			  catch(ClassNotFoundException ex)
			   {
			    System.out.println("Class not found");
			   }
			  catch(Exception ex)
			  {
               System.out.println("Exception raised is:"+ex);
			  }			  
		}		
	//------------------------------------------------------------------- Ending with  deleteRecord() -------	
	//=============================================================== Starting with ButtonHandler class  ========	
	
	class ButtonHandler implements ActionListener 
		{
  			public void actionPerformed(ActionEvent ev)
			{
					
   				String s=ev.getActionCommand(); 	
				if(s.equals("Click to Continue"))
				{
					cont.setEnabled(false);
					displayPanel1();
					tbPane.setSelectedIndex(1);
					tbPane.removeTabAt(0);
				}
   				else if(s=="LOGIN") //Login is Clicked
				{
							
					verifyLogin();					
					tbPane.setSelectedIndex(0);
					tlogname.setText("");
				}  
				else if(s.equals("SAVE RECORD")) //Save Record is Clicked
				{
					
					addRecord();
					String snametemp = tsname.getText();
				}	
				else if(s.equals("MODIFY")) //Modify Record is Clicked
				{					
					int student_id=Integer.parseInt(selname.substring(0,2));
					updateRecord(student_id,selname);
					int x=ctr_val;
					
					for(int y=x;y>1;y--)
					{
						cb_sname.removeItemAt(y);
						
				    }
					cb_sname.addItem("Select Student Name");
				    cb_sname.removeItemAt(0);
				    cb_sname.removeItemAt(1);
				    accessStudName();
				    cb_sname.removeItemAt(1);
				   				
				}
				else if(s.equals("DELETE"))	//Delete Record Button is Clicked
				{
					dlgCPane.setLayout(new FlowLayout());					
					dlgCPane.add(jLabeldlg);
					jLabeldlg.setFont(tFont);
					dlgCPane.add(delit);
					delit.addActionListener(new ButtonHandler());		
					dlgCPane.add(delno);
					delno.addActionListener(new ButtonHandler());
					dlg.setBounds(300, 200, 250, 120);
					dlg.show();
				}
				else if(s.equals("YES"))	//Yes button is clicked in Delete dialog box
				{
					dlg.dispose();
					selname = cb_sname.getSelectedItem().toString();
					int student_id=Integer.parseInt(selname.substring(0,2));
  					deleteRecord(student_id);
  					int x=ctr_val;
					for(int y=x;y>1;y--)
					{
						cb_sname.removeItemAt(y);
				    }
					cb_sname.addItem("Select Student Name");
				    cb_sname.removeItemAt(0);
				    cb_sname.removeItemAt(1);
				    accessStudName();
				    cb_sname.removeItemAt(1);
				}
				
				else if(s.equals("NO"))		//No button is clicked in the Delete dialog box
				{
					dlg.dispose();
				}								
			}
 		}
		//------------------------------------------------------------- Ending with the ButtonHandler --------	
		//=========================================================== Starting with the MenuItemHandler ======
 		
		class MenuItemHandler implements ActionListener 
		{
  			public void actionPerformed(ActionEvent ev)
			{
   				String s=ev.getActionCommand();
   				if(s=="Exit")
				{
					//close window on menuitem exit
    				System.exit(0);
   				}								
  			}					
 		}
		//----------------------------------------------------------- Ending with the MenuItemHandler ------
		//=========================================================== Starting with the WindowEventHandler ===
 		class WindowEventHandler extends WindowAdapter 
		{
  			public void windowClosing(WindowEvent e)
			{
				//Closing the window on exit
   				System.exit(0);
  			}
 		}
		//----------------------------------------------------------- Ending with WindowEventHandler ---
		//=========================================================== Starting with RadioListener ========
		
		class RadioListener implements ActionListener 
		{
      		public void actionPerformed(ActionEvent e) 
			{
				  gender = e.getActionCommand();
				 
				  condsel = e.getActionCommand();
				  
		    }
		}
		//----------------------------------------------------------- Ending with the RadioListener --------
		//=========================================================== Starting with the ComboBoxListener ========
		
		class ComboBoxListener implements ItemListener  
		{
			public ComboBoxListener()
			{
				super();
			}
      		public void itemStateChanged(ItemEvent e) 
			{				
		    	str = (String)e.getItem();
				if (e.getSource().equals(cb_fatheroccupation))
    			{
    				foccupation = cb_fatheroccupation.getSelectedItem().toString();
    			}
				if (e.getSource().equals(mcb_fatheroccupation))
    			{
    				foccupation = mcb_fatheroccupation.getSelectedItem().toString();
    			}
				if (e.getSource().equals(cb_course))
    			{
    				course = cb_course.getSelectedItem().toString();
    			}
				if (e.getSource().equals(mcb_course))
    			{
    				course = mcb_course.getSelectedItem().toString();
    			}
    			if (e.getSource().equals(cb_year))
    			{
    				year = cb_year.getSelectedItem().toString();
    			}
				if (e.getSource().equals(mcb_year))
    			{
    				year = mcb_year.getSelectedItem().toString();
    			}
				if (e.getSource().equals(cb_sname))
    			{	
	    
					selname = cb_sname.getSelectedItem().toString();
  					accessModifiedDatabase(Integer.parseInt(selname.substring(0,2)));					
    			}
				if (e.getSource().equals(jstudID))
    			{
					studID = jstudID.getSelectedItem().toString();
    			}
				if (e.getSource().equals(jeq))
    			{
					eq = jeq.getSelectedItem().toString();
    			}
		    }
		}
		//----------------------------------------------------------- Ending with the ComboBoxListener --------
		//=========================================================== Starting with the CheckBoxListener =====		
		
		class CheckBoxListener implements ItemListener 
		{
    		
			public void itemStateChanged(ItemEvent e) 
    		{
        		Object source = e.getItemSelectable();
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==dmc))
       			{
					dmcsel = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==dmc))
       			{
					dmcsel = 0;
      			}					
				if ((e.getStateChange() == ItemEvent.SELECTED)  && (source==degree))
       			{
					degreesel = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==degree))
       			{
					degreesel = 0;
      			}					
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==ncc))
       			{
					ncccfsel = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==ncc))
       			{
					ncccfsel = 0;
      			}					
				if ((e.getStateChange() == ItemEvent.SELECTED)  && (source==charcerti))
       			{
					charcfsel = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==charcerti))
       			{
					charcfsel = 0;
      			}						
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==mdmc))
       			{
					mdmcsel = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==mdmc))
       			{
					mdmcsel = 0;
      			}					
				if ((e.getStateChange() == ItemEvent.SELECTED)  && (source==mdegree))
       			{
					mdegreesel = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==mdegree))
       			{
					mdegreesel = 0;
      			}					
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==mncc))
       			{
					mnccsel = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==mncc))
       			{
					mnccsel = 0;
      			}					
				if ((e.getStateChange() == ItemEvent.SELECTED)  && (source==mcharcerti))
       			{
					mcharcfsel = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==mcharcerti))
       			{
					mcharcfsel = 0;
      			}		
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==ckstudentID))
       			{
					selstudentID = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==ckstudentID))
       			{
					selstudentID = 0;
      			}	
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==ckstudentname))
       			{
					selstudentname = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==ckstudentname))
       			{
					selstudentname = 0;
      			}	
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==ckpreaddress))
       			{
					selstudentpreadd = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==ckpreaddress))
       			{
					selstudentpreadd = 0;
      			}	
      			if ((e.getStateChange() == ItemEvent.SELECTED) && (source==ckpermaaddress))
       			{
					selstudentpermaadd = 1;
      			}
      			if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==ckpermaaddress))
       			{
					selstudentpermaadd = 0;
      			}	
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==ckfathername))
       			{
					selfathername = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==ckfathername))
       			{
					selfathername = 0;
      			}	
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==ckgender))
       			{
					selgender = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==ckgender))
       			{
					selgender = 0;
      			}	
				if ((e.getStateChange() == ItemEvent.SELECTED) && (source==ckdob))
       			{
					seldob = 1;
      			}
				if ((e.getStateChange() == ItemEvent.DESELECTED)  && (source==ckdob))
       			{
					seldob = 0;
      			}	
										
    		}			
		}
}

⌨️ 快捷键说明

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