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

📄 student.java

📁 student information management system.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import javax.swing.table.*;
public class Student extends JFrame 
{		
 		//Declaring Variables
		boolean inAnApplet = true;   
		final boolean shouldFill = true;
    	final boolean shouldWeightX = true;

    	//Welcome panel TAB
		final static String panelstr0 = " Welcome ";
    				
		//Login panel TAB
		final static String panelstr1 = " LOGIN ";
		
		//Student Detail panel TAB		
		final static String panelstr2 = " ADD STUDENT DETAILS ";
		
		//Modify or Delete Student Details panel TAB		
		final static String panelstr3 = " MODIFY / DELETE STUDENT DETAILS ";
				
		//Applying courier new fonts for the controls used		
		Font dFont = new Font("courier new",Font.PLAIN,12);
		Font tFont = new Font("courier new",Font.BOLD,14);
		
		//Applying listners for handling radio button events
		RadioListener alistener = new RadioListener();	
		
		//Applying listners for handling check box events
		CheckBoxListener ckblistener = new CheckBoxListener();
		
		//Applying listners for handling combo box events
		ComboBoxListener cmblistener = new ComboBoxListener();
		
		//Applying gridbag layout
		GridBagLayout grid = new GridBagLayout();
        GridBagConstraints gbc1 = new GridBagConstraints();	
		GridBagConstraints gbc2 = new GridBagConstraints();	
		GridBagConstraints gbc3 = new GridBagConstraints();	
		
		//Dialog Box to ask delete confirmation messages 
		Container cpane = getContentPane();		
		JDialog dlg = new JDialog((Frame) null, " Delete Confirmation!!!", true);
		Container dlgCPane = dlg.getContentPane();		
		
		//Grouping the Radio Buttons 
		ButtonGroup bg1 = new ButtonGroup();
		ButtonGroup bg2 = new ButtonGroup();
		ButtonGroup bg3 = new ButtonGroup();
		
		// Declaring the Labels
		JLabel jwelcome, jlogin, jpass, jstudentname, jpreaddress, jpermaaddress,  jfathername, jgender, jcourse, jyear,  jlabel, jdob, jfatheroccupation, jphone,jlabel111;
		JLabel jmstudentname, jmpreaddress, jmpermaaddress,  jmfathername, jmgender, jmcourse, jmyear,  jmlabel, jmdob, jmfatheroccupation, jmphone; 
		JLabel jLabeldlg = new JLabel("Are you sure?");
				
		// Declaring the Radio buttons 
		JRadioButton male, female, m_male, m_female;		
			
		// Declaring the Check boxes 
		JCheckBox dmc, degree, charcerti, ncc, mdmc, mdegree, mcharcerti, mncc;	
		JCheckBox ckstudentID, ckstudentname, ckpreaddress, ckpermaaddress, ckfathername, ckgender, ckdob;
		
		// Declaring the combo boxes 
		JComboBox cb_course, cb_year ,mcb_course, mcb_year, cb_sname, cb_fatheroccupation, mcb_fatheroccupation;	
		JComboBox jstudID, jeq;
		
		// Declaring the text boxes 
		JTextField tlogname, tsname, tspreaddress, tspermaaddress, tsphone, tsdob, tsfathername, tsfatheroccupation;
		JPasswordField tlogpass = new JPasswordField(40);	
		JTextField tmname, tmpreaddress, tmpermaaddress, tmphone, tmdob, tmfathername, tmfatheroccupation;
					
		// Declaring the String type variables
		String driver="sun.jdbc.odbc.JdbcOdbcDriver";
		String url="jdbc:odbc:student";		
		String title_dialog = "Student Record Added";
		String fail_dialog = "Login Error";
		String add_dialog = "Database Record Added";
		String modify_dialog = "Database Record Updated";
		String del_dialog = "Database Record Deleted";
		String gender = "male";
		String year = "I Year";
		String course = "BSc(Comp. Sc.)";
		String foccupation = "Govt. Employee";
		String currentname = "";
		String tempname = "";
		String qry = "";
		String condsel="No Condition", studID="StudentID", eq="=";	
		String query1, query2, query3, query4, query5, query6, query7, message_dialog, nsel, selname, reg_no,str;
		
		 //Declaring the Integer type variables
		int dmcsel, degreesel, charcfsel, ncccfsel, mdmcsel, mdegreesel, mcharcfsel, mnccsel;
		int type_dialog = JOptionPane.PLAIN_MESSAGE;
		int ctr_val=0,selstudentID=0,selstudentname=0,selstudentpreadd=0, selstudentpermaadd, selfathername=0,selgender=0, seldob=0;
		
		//Declaring the JPanel & Tabbed panes 
		JPanel pan0, pan1, pan2, pan3;
		JTabbedPane tbPane = new JTabbedPane();
		
		// Declaring the Submit Buttons 		
		JButton delit = new JButton("YES");
		JButton delno = new JButton("NO");
		JButton login, cont, save, mod_button, del;
			
		//Building JTable for student reports 
		Object[] data = new Object[5];
	   	DefaultTableModel defaulttablemodel = new DefaultTableModel();
   		JTable jtable = new JTable(defaulttablemodel);	
		
   		//Starting with the main() method   													
		public static void main(String args[])
 		{
  			Student stud = new Student();
 		}
		//------------------------- Ending with the main() method -----------------
		
		//========================= Starting with the Student constructor =========
 		public Student() 
 		{
			// Declaring title for the application 
  			super("STUDENT INFORMATION MANAGEMENT SYSTEM"); 
  			setUp();
  			pack();
  			addWindowListener(new WindowEventHandler());
  			setSize(640,480);
  			show();
 		}
		//--------------------------Ending with the Student Constructor--------------
		
		//Starting the setUp() method to create the File menu on panel
		void setUp() 
 		{
  			setUpMenuBar(); //Calling the setUpMenuBar() to create the Exit Menu item
			displayPanel0();	//Calling a method that creates a panel and displays the Exit menu item
			cpane.add(tbPane, BorderLayout.CENTER);
  		}
		//------------Ending with the setUp() method---------
		
		//-----------Starting with the setUpMenuBar() method to create File menu
 		void setUpMenuBar() 
		{
  			  MenuBar mBar = new MenuBar();
			  Menu mfile = new Menu("File");		
			  		// Creating the Exit menu item
			  		MenuItem xfile = new MenuItem("Exit");		
						// Handling this menu item on click event to Exit 	  			  
			  			xfile.addActionListener(new MenuItemHandler()); 
			  			mfile.add(xfile);					
			  		mBar.add(mfile);
			  setMenuBar(mBar);
 		}	
//--------------------------Ending with the setUpMenuBar() method--------------				

//-----------Starting with the displayPanel0() method to create the Welcome panel

		void displayPanel0()
		{
			pan0 = new JPanel(); //Creating a Welcome Panel
			pan0.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),""));
			pan0.setFont(tFont);
			pan0.setLayout(grid);  						
			jwelcome = new JLabel("Student Information Management  System ");	
			Font f = new Font("Helvetica", Font.BOLD + Font.ITALIC, 30);
			jwelcome.setFont(f);
			gbc1.ipady=1;
			gbc1.ipadx=1;
			gbc1.gridx=0;
			gbc1.gridy=1;
			grid.setConstraints(jwelcome,gbc1);
			pan0.add(jwelcome);
			
			jlabel111=new JLabel("      					");
			gbc1.ipady=1;
			gbc1.ipadx=1;
			gbc1.gridx=0;
			gbc1.gridy=2;
			grid.setConstraints(jlabel111,gbc1);
			pan0.add(jlabel111);
			cont = new JButton("Click to Continue");
						gbc1.ipady = 1;       						
						gbc1.ipadx = 1;  
						gbc1.gridx = 0;       						     
			        	gbc1.gridy = 3;    				
		        		grid.setConstraints(cont, gbc1);
			pan0.add(cont);										
			cont.addActionListener(new ButtonHandler());  
			tbPane.addTab(panelstr0, pan0);
	 }				
//--------------------------Ending with the displayPanel0() method--------------				

//-----------Starting with the displayPanel1() method to create the Login panel

	 	void displayPanel1()
		{
			pan1 = new JPanel(); //LOGIN TAB
			pan1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),""));
			pan1.setFont(tFont);
			pan1.setLayout(grid);  						
				jlogin = new JLabel("Login Name ");
				jlogin.setFont(dFont);// Make this Data Font that we declared before
				    //gbc1.weightx = 0.0;    //Horizontal Space not required here		             						
			        gbc1.weighty = 0.0;   	  //Vertical Space	
					gbc1.ipady = 2;       	  //Height of Component				
					gbc1.ipadx = 2; 		  //Width of Component
			        gbc1.anchor = GridBagConstraints.WEST; 	
			      	gbc1.gridwidth = 1;   	  //1 columns wide				
			        gbc1.gridx = 0;       	  //aligned with login 0  -- Very Important 					   
			        gbc1.gridy = 0;       	  //0th Row  	
					// Adding all these features to this Label, jlogin
			        grid.setConstraints(jlogin, gbc1);
					// Adding the Label "jlogin" onto the LOGIN TAB
		        pan1.add(jlogin);				
				tlogname = new JTextField(20);
			    	gbc1.ipady = 2;       						
					gbc1.ipadx = 2;       						
		        	gbc1.weighty = 0.0;   						
		        	gbc1.anchor = GridBagConstraints.WEST; 	
		       		gbc1.gridwidth = 5;   						
		        	gbc1.gridx = 1;       						    
		        	gbc1.gridy = 0;       						
		        	grid.setConstraints(tlogname, gbc1);
		        pan1.add(tlogname);				
				jpass = new JLabel("Password");
				jpass.setFont(dFont);
			        gbc1.ipady = 2;       						
					gbc1.ipadx = 2;       						
			        gbc1.weighty = 0.0;   						
			        gbc1.anchor = GridBagConstraints.WEST; 	
			        gbc1.gridwidth = 5;   						
			        gbc1.gridx = 0;       						     
			        gbc1.gridy = 1;       						
			        grid.setConstraints(jpass, gbc1);
			     pan1.add(jpass);				
				tlogpass = new JPasswordField(20);
			    	gbc1.ipady = 2;       						
					gbc1.ipadx = 2;       						
		        	gbc1.weighty = 0.0;   						
		        	gbc1.anchor = GridBagConstraints.WEST; 	
		       		gbc1.gridwidth = 2;   						
		        	gbc1.gridx = 1;       						     
		        	gbc1.gridy = 1;       						
		        	grid.setConstraints(tlogpass, gbc1);
		        pan1.add(tlogpass);				
				login = new JButton("LOGIN");
		        	gbc1.ipady = 2;       						
					gbc1.ipadx = 2;       						
		        	gbc1.weighty = 0.0;   						
		        	gbc1.anchor = GridBagConstraints.CENTER; 	        
					gbc1.gridwidth = 1;   						
		        	gbc1.gridx = 1;       						      
		        	gbc1.gridy = 2;       						
		        	grid.setConstraints(login, gbc1);
		        pan1.add(login);										
				login.addActionListener(new ButtonHandler());  				
			tbPane.addTab(panelstr1, pan1);
			}
		//------------------------------------------------------------ Ending with displayPanel1() method -----------
		//============================================================ Starting with displayPanel2() method ===========
		void displayPanel2() //ADD STUDENT  DETAILS TAB 
		{
				   pan2 = new JPanel();
				   pan2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),""));
				   pan2.setLayout(grid);					  		   
				   jstudentname = new JLabel("Student Name");	
				   jstudentname.setFont(dFont);		
						gbc1.fill = GridBagConstraints.BOTH;		
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 0;       						     
			        	gbc1.gridy = 1;       						
			        	grid.setConstraints(jstudentname, gbc1);
			       	pan2.add(jstudentname);															
					tsname = new JTextField(20);
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 1;       						     
			        	gbc1.gridy = 1;       						
			        	grid.setConstraints(tsname, gbc1);				
					pan2.add(tsname);									
					jdob = new JLabel("Date of Birth");
					jdob.setFont(dFont);				
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 0;       						     
			        	gbc1.gridy = 2;       						
			        	grid.setConstraints(jdob, gbc1);				
					pan2.add(jdob);													
					tsdob = new JTextField(20);	
					gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 1;       						     
			        	gbc1.gridy = 2;       						
			        	grid.setConstraints(tsdob, gbc1);				
					pan2.add(tsdob);				
					jfathername = new JLabel("Father Name");	
						jfathername.setFont(dFont);				
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 0;       						     
			        	gbc1.gridy = 3;       						
			        	grid.setConstraints(jfathername, gbc1);				
					pan2.add(jfathername);	
					tsfathername = new JTextField(20);
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 1;       						     
			        	gbc1.gridy = 3;       						
			        	grid.setConstraints(tsfathername, gbc1);				
					pan2.add(tsfathername);				
					jfatheroccupation = new JLabel("Father Occupation");	
					jfatheroccupation.setFont(dFont);	
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 0;       						     
			        	gbc1.gridy = 4;       						
			        	grid.setConstraints(jfatheroccupation, gbc1);
			        	pan2.add(jfatheroccupation);					
			        	cb_fatheroccupation = new JComboBox();
						cb_fatheroccupation.setFont(dFont);	
						// Adding Elements to combo box
				 		cb_fatheroccupation.addItem(" Govt. Employee ");
		    			cb_fatheroccupation.addItem(" Self Employed ");
						cb_fatheroccupation.addItem(" Business ");
						gbc1.fill = GridBagConstraints.BOTH;
						gbc1.insets = new Insets(10,0,0,30);  		
		    			gbc1.ipady = 2;     
						gbc1.ipadx = 2;		
		       	        gbc1.gridx = 1;	
		        		gbc1.gridy = 4;	
						cb_fatheroccupation.addItemListener(new ComboBoxListener());			
		        		grid.setConstraints(cb_fatheroccupation, gbc1);
		        	    pan2.add(cb_fatheroccupation);		
					jpreaddress = new JLabel("Present Address");	
						jpreaddress.setFont(dFont);				
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 0;       						     
			        	gbc1.gridy = 5;       						
			        	grid.setConstraints(jpreaddress, gbc1);		
					pan2.add(jpreaddress);
					tspreaddress = new JTextField(20);
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 1;       						     
			        	gbc1.gridy = 5;   
						grid.setConstraints(tspreaddress, gbc1);	
					pan2.add(tspreaddress);	
					jpermaaddress = new JLabel("Permanent Address");	
						jpermaaddress.setFont(dFont);				
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 0;       						     
			        	gbc1.gridy = 6;       						
			        	grid.setConstraints(jpermaaddress, gbc1);		
					pan2.add(jpermaaddress);
					tspermaaddress = new JTextField(20);
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 1;       						     
			        	gbc1.gridy = 6;   
						grid.setConstraints(tspermaaddress, gbc1);	
					pan2.add(tspermaaddress);	
					jphone = new JLabel(" Telephone Number ");	
					jphone.setFont(dFont);		
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 0;       						     
			        	gbc1.gridy = 7;       						
			        	grid.setConstraints(jphone, gbc1);		
					pan2.add(jphone);
				tsphone = new JTextField(20);
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  
						gbc1.gridx = 1;       						     
			        	gbc1.gridy = 7;   
						grid.setConstraints(tsphone, gbc1);	
					pan2.add(tsphone);						
					// Checking the default gender as male by using 'true' 
					jgender = new JLabel("Gender");	
					jgender.setFont(dFont);	
						gbc1.ipady = 2;       						
						gbc1.ipadx = 2;  

⌨️ 快捷键说明

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