Java program synthesis Case: Student File Management module of the management system of the Dean's Office __java

Source: Internet
Author: User
Tags gettext odbc

1. This is a Portal framework class for student information systems. Studentframe is the top-level window frame. Through seven button controls to enter the different classes, different departments of the student information system.

Class Studentmanageframe extends JPanel {private static final long serialversionuid = 1L;

	static final int WIDTH = 400;

	static final int HEIGHT = 200;

	JFrame Studentframe;
		Public Studentmanageframe () {studentframe = new JFrame ();

		Studentframe.setbackground (Color.Black);
		Studentframe.settitle ("Student Information Management system");
		Studentframe.setdefaultcloseoperation (Jframe.exit_on_close);
		Studentframe.setsize (WIDTH, HEIGHT);
		Toolkit kit = Toolkit.getdefaulttoolkit ();
		Dimension screensize = Kit.getscreensize ();
		int width = screensize.width;
		int height = screensize.height;
		int x = (width-width)/2;
		int y = (height-height)/2;
		Studentframe.setlocation (x, y);
		Studentframe.setvisible (TRUE);
		Studentframe.setresizable (FALSE);
		Studentframe.add (this, borderlayout.center);
		JButton Computerone = new JButton ("English Department class One student Information System");
		JButton computertwo = new JButton ("Second class student information system of English Department");
		JButton computerthree = new JButton ("One class student information system of Law department"); JButton BioOne = new JButton ("Second class student information system of Law Department");
		JButton Mechone = new JButton ("Three class student information system of Law department");
		JButton mechtwo = new JButton ("Mathematics Department class One student Information System");
		JButton mechthree = new JButton ("Second class student information system of Mathematics Department");
		JLabel title = new JLabel ("Student Information management");
		JLabel Banket1 = new JLabel ();
		JLabel Banket2 = new JLabel ();
		GridBagLayout lay = new GridBagLayout ();
		SetLayout (lay);
		gridbagconstraints constraints = new gridbagconstraints ();
		Constraints.fill = Gridbagconstraints.none;
		Constraints.anchor = Gridbagconstraints.east;
		CONSTRAINTS.WEIGHTX = 2;
		Constraints.weighty = 5;
		JPanel JP = new JPanel ();
		Jp.setlayout (New GridLayout (1, 3));
		Jp.add (BANKET1);
		Jp.add (title);
		Jp.add (Banket2);
		Studentframe.add (JP, Borderlayout.north); Add (computerone, Constraints, 0, 1, 1, 1);
		Add controls by using grid group layouts (computertwo, Constraints, 0, 2, 1, 1);
		Add (computerthree, Constraints, 0, 3, 1, 1);
		Add (bioone, Constraints, 0, 4, 1, 1);
		Add (Mechone, Constraints, 1, 1, 1, 1);
		Add (Mechtwo, Constraints, 1, 2, 1, 1); Add (Mechthree, Constraints, 1, 3, 1, 1); /Click this button to enter the English Department class One student information System Computerone.addactionlistener (new ActionListener () {public void actionperformed (Actioneven
				T Event) {String sql = ' SELECT * from Studentinfo where class= ' class ' and major= ' English Department ';

			Show_student info = new Show_student ("English Department class One student Information System", SQL);
		}
		}); /Click this button to enter the second class student information System Computertwo.addactionlistener (new ActionListener () {public void actionperformed (Actioneven
				T Event) {String sql = ' SELECT * from Studentinfo where class= ' second class ' and major= ' English Department ';
			Show_student studentinformation = new Show_student ("Class II Student Information System", SQL);
		}
		}); /Click this button to enter the Law department three Class student information System Computerthree.addactionlistener (new ActionListener () {public void actionperformed (Actionev
				Ent Event) {String sql = "SELECT * from Studentinfo where class= ' class ' and major= ' law department '";
			Show_student studentinformation = new Show_student ("Law Faculty class One student Information System", SQL);
		}
		}); /Click this button to enter the Law department Class A student information System Bioone.addactionlistener (new ActionListener () {public void ACtionperformed (ActionEvent Event) {String sql = "SELECT * from Studentinfo where class= ' second class ' and major= ' law department '";
			Show_student studentinformation = new Show_student ("Second class student information system of Law department", SQL);
		}
		}); /Click this button to enter the mechanical machine Department class One student information System Mechone.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent E
				VENT) {String sql = "SELECT * from Studentinfo where class= ' class three ' and major= ' law department '";
			Show_student studentinformation = new Show_student ("Three class student information system of Law department", SQL);
		}
		}); /Click this button to enter the Math Department class One student information System Mechtwo.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent Eve
				NT) {String sql = ' SELECT * from Studentinfo where class= ' class ' and major= ' mathematics Department ';
			Show_student studentinformation = new Show_student ("Mathematics Department class One student Information System", SQL);
		}
		}); /Click this button, Mathematics department second Class student information System Mechthree.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent Eve NT) {String sql = ' SELECT * from Studentinfo where class= ' second class ' and MAJor= ' Mathematics department ';
			Show_student studentinformation = new Show_student ("The second class student information system of Mathematics Department", SQL);
	}
		}); 
		public void Add (Component C, gridbagconstraints constraints, int x, int y, int w, int h) {constraints.gridx = x;
		Constraints.gridy = y;
		Constraints.gridwidth = W;
		Constraints.gridheight = h;
	Add (c, constraints);
 }
}

2. Student Class

Class Studentbean {
		private String name;


		Private String code;


		Private String sexy;


		Private String birthday;


		Private String address;


		Private String age;


		private String grade;


		Private String major;


		Studentbean (string name, string code) {
			this.name = name;
			This.code = code;
		}

3. Deposit student information in the database

Import Java.util.Vector;

Import java.sql.*;
		Class From_student {public Vector getstudent (Connection con, String sql) {vector v = new vector ();
			try {Statement st = con.createstatement ();
			ResultSet rs = st.executequery (SQL);
				while (Rs.next ()) {String name = rs.getstring (1);
				String code = rs.getstring (2);
				String sexy = rs.getstring (3);
				String age = rs.getstring (4);
				String address = rs.getstring (5);
				String birthday = rs.getstring (6);
				String grade = rs.getstring (7);
				String major = Rs.getstring (8);
				Studentbean ss = new Studentbean (name, code);
				Ss.setsexy (sexy);
				Ss.setmajor (Major);
				Ss.setbirthday (birthday);
				Ss.setaddress (address);
				Ss.setage (age);
				Ss.setgrade (grade);
			V.add (ss);
		} rs.close ();
		catch (Exception e) {e.printstacktrace ();
	} return v;
		Public Studentbean GetObject (Connection con, String stname) {Studentbean SST = null;
			try {Statement st = con.createstatement (); Stringsql = "SELECT * from Studentinfo where stname= '" + stname + "'";
			ResultSet rs = st.executequery (SQL);
			/from the GetString method in the result set, extract the data from the table field in the database////and assign the extracted data to the student object.
				/Finally, the student object is stored in the vector data structure while (Rs.next ()) {String code = rs.getstring (2);
				String sexy = rs.getstring (3);
				String age = rs.getstring (4);
				String address = rs.getstring (5);
				String birthday = rs.getstring (6);
				String grade = rs.getstring (7);
				String major = Rs.getstring (8);
				SST = new Studentbean (stname, code);
				Sst.setsexy (sexy);
				Sst.setmajor (Major);
				Sst.setbirthday (birthday);
				Sst.setaddress (address);
				Sst.setage (age);
			Sst.setgrade (grade);

		} rs.close ();
		catch (Exception e) {e.printstacktrace ();
	return SST;

		////By setting the database URL, password, username to establish a connection with the database public Connection getconnection () {Connection con = null;
			try {class.forname ("sun.jdbc.odbc.JdbcOdbcDriver"); Load ODBC data Driven con = drivermanager.getconnection ("Jdbc:odbc:myodbc", "", "");
		catch (SQLException e) {e.printstacktrace ();
		catch (ClassNotFoundException ex) {ex.printstacktrace ();
	return con;
 }
}

4. This is a student information system add information Framework class outputs different information leaders separately through nine text fields. Add data to the database by adding a button.

/** main Running class * Main refers to the main frame * setdefaultcloseoperation means to make the button in the upper-right corner of the frame valid * Show let the frame be displayed * * */import java.awt.*;
Import java.awt.event.*;
Import java.sql.*;
Import Java.util.Vector;

Import javax.swing.*; /** * This is a student information system add information Framework class outputs different information leaders separately through nine text fields.
 Add data to the database by adding a button. * The layout here is set by the grid group layout manager to set the student object SS to static when loopback to the information interface.
 When you place a new object, its value changes.

	* * Class Student_frame extends JPanel {String codetext;

	String Agetext;

	String Sexytext;

	String Birthdaytext;

	String Addresstext;

	String Gradetext;

	String Majortext;

	Public final JTextField nameinput = new JTextField (10);

	Private static final long serialversionuid = 1L;

	static final int WIDTH = 700;

	static final int HEIGHT = 400;

	Static Studentbean SS;

	JFrame Studentbeanaddframe;
		public void Add (Component C, gridbagconstraints constraints, int x, int y, int w, int h) {constraints.gridx = x;
		Constraints.gridy = y;
		Constraints.gridwidth = W;
		Constraints.gridheight = h;
	Add (c, constraints); Public Student_frame () {sTudentbeanaddframe = new JFrame ();
		Studentbeanaddframe.settitle ("Student add System");
		Studentbeanaddframe.setdefaultcloseoperation (Jframe.exit_on_close);
		Studentbeanaddframe.setsize (WIDTH, HEIGHT);
		Toolkit kit = Toolkit.getdefaulttoolkit ();
		Dimension screensize = Kit.getscreensize ();
		int width = screensize.width;
		int height = screensize.height;
		int x = (width-width)/2;
		int y = (height-height)/2;
		Studentbeanaddframe.setlocation (x, y);
		Studentbeanaddframe.setvisible (TRUE);
		Studentbeanaddframe.setresizable (FALSE);
		Studentbeanaddframe.add (this, borderlayout.center);
		GridBagLayout lay = new GridBagLayout ();
		SetLayout (lay);
		JLabel name = new JLabel (New ImageIcon ("d://abc//11.jpg"));
		JLabel code = new JLabel (New ImageIcon ("d://abc//13.jpg"));
		JLabel sexy = new JLabel (New ImageIcon ("d://abc//12.jpg"));
		JLabel age = New JLabel (New ImageIcon ("d://abc//14.jpg"));
		JLabel birthday = new JLabel (New ImageIcon ("d://abc//15.jpg")); JLabel address = new JLabel (newImageIcon ("d://abc//16.jpg"));
		JLabel grade = new JLabel (New ImageIcon ("d://abc//17.jpg"));
		JLabel major = new JLabel (New ImageIcon ("d://abc//18.jpg"));
		Final JTextField codeinput = new JTextField (10);
		Final JTextField sexyinput = new JTextField (10);
		Final JTextField ageinput = new JTextField (10);
		Final JTextField birthdayinput = new JTextField (10);
		Final JTextField addressinput = new JTextField (10);
		Final JTextField gradeinput = new JTextField (10);
		Final JTextField majorinput = new JTextField (10);
		JLabel title = new JLabel ("Basic information that students are added");
		JButton Additionbutton = new JButton ("Add");
		gridbagconstraints constraints = new gridbagconstraints ();
		Constraints.fill = Gridbagconstraints.none;
		CONSTRAINTS.WEIGHTX = 4;
		Constraints.weighty = 6; Add (title, constraints, 0, 0, 4, 1);
		Add controls using the Grid group layout (name, constraints, 0, 1, 1, 1);
		Add (Code, constraints, 0, 2, 1, 1);
		Add (sexy, Constraints, 0, 3, 1, 1);
		Add (age, Constraints, 0, 4, 1, 1); Add (Nameinput, ConstrAints, 1, 1, 1, 1);
		Add (Codeinput, Constraints, 1, 2, 1, 1);
		Add (Sexyinput, Constraints, 1, 3, 1, 1);
		Add (Ageinput, Constraints, 1, 4, 1, 1);
		Add (Birthday, Constraints, 2, 1, 1, 1);
		Add (Address, Constraints, 2, 2, 1, 1);
		Add (grade, Constraints, 2, 3, 1, 1);
		Add (Major, Constraints, 2, 4, 1, 1);
		Add (Birthdayinput, Constraints, 3, 1, 1, 1);
		Add (Addressinput, Constraints, 3, 2, 1, 1);
		Add (Gradeinput, Constraints, 3, 3, 1, 1);
		Add (Majorinput, Constraints, 3, 4, 1, 1);
		Add (Additionbutton, Constraints, 0, 5, 4, 1); /Assign the information in each text field to a variable, and then store the variable as a value in the database table//Finally, store the values in the Student object, and the student object is a static object Additionbutton.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent Event) {try {String nametext = Nameinput.gettext (
					);
					Codetext = Codeinput.gettext ();
					Agetext = Ageinput.gettext ();
					Sexytext = Sexyinput.gettext ();
					Birthdaytext = Birthdayinput.gettext ();
					Addresstext = Addressinput.gettext (); Gradetext = GraDeinput.gettext ();
					Majortext = Majorinput.gettext ();
					From_student store = new From_student ();
					Connection con = store.getconnection ();
					Statement st = Con.createstatement (); String sql = "INSERT into studentinfo values (' + Nametext +" ', ' "+ Codetext +" ', ' "+ Sexytext +" ', ' "+ A
					Getext + "', '" + Addresstext + "', '" + Birthdaytext + "', '" + Gradetext + "', '" + Majortext + "');
					St.executeupdate (SQL);
					SS = new Studentbean (Nametext, Codetext);
					Ss.setage (Agetext);
					Ss.setsexy (Sexytext);
					Ss.setaddress (Addresstext);
					Ss.setbirthday (Birthdaytext);
					Ss.setgrade (Gradetext);
					Ss.setmajor (Majortext);
					Vector vec = new vector ();
				Vec.add (ss);
			catch (Exception e) {} studentbeanaddframe.dispose ();
	}
		});
 }
}

5.* This is the framework class of student information system

Import javax.swing.*;
Import java.awt.*;
Import java.awt.event.*;
Import Java.util.Vector;

Import java.sql.*;
 /** This is the framework class of the Student information system * Studentinfoframe is the top-level window frame.
 * Through eight text field controls, you can display students ' information in different classes and departments respectively. * Three button controls produce three different history events of action events, respectively, additions, deletions, and updates. Addition is added. Delete is deleted, update is updated * There are two layout managers in the layout, one is the lay, the grid group layout.
 One is JP is the GridLayout layout.
 * Through different SQL statements into different classes and departments of the management system. * Use the data in the database to pilot into the VEC. The data in the VEC is then imported into the student class.

	Finally, the data output * */class Show_student extends JPanel {private static final long serialversionuid = 1L;

	static final int WIDTH = 700;

	static final int HEIGHT = 400;

	Final JComboBox Nameinput;

	Final JTextField Codeinput;

	Final JTextField Sexyinput;

	Final JTextField Birthdayinput;

	Final JTextField Ageinput;

	Final JTextField Addressinput;

	Final JTextField Gradeinput;

	Final JTextField Majorinput;

	JFrame Studentinfoframe;

	From_student store = new From_student ();

	Connection con = store.getconnection ();

	Student_frame af = new Student_frame (); public void Add (Component C, Gridbagconstraints constraints, int x, int y, int w, int h) {constraints.gridx = x;
		Constraints.gridy = y;
		Constraints.gridwidth = W;
		Constraints.gridheight = h;
	Add (c, constraints);
		Public show_student (String str, String sql) {studentinfoframe = new JFrame ();
		Studentinfoframe.settitle (str);
		Studentinfoframe.setdefaultcloseoperation (Jframe.exit_on_close);
		Studentinfoframe.setsize (WIDTH, HEIGHT);
		Toolkit kit = Toolkit.getdefaulttoolkit ();
		Dimension screensize = Kit.getscreensize ();
		int width = screensize.width;
		int height = screensize.height;
		int x = (width-width)/2;
		int y = (height-height)/2;
		Studentinfoframe.setlocation (x, y);
		Studentinfoframe.setvisible (TRUE);
		Studentinfoframe.setresizable (FALSE);
		Studentinfoframe.add (this, borderlayout.center);
		GridBagLayout lay = new GridBagLayout ();
		SetLayout (lay);
		JLabel name = new JLabel (New ImageIcon ("d://abc//11.jpg"));
		JLabel code = new JLabel (New ImageIcon ("d://abc//13.jpg")); JLabel Sexy = new JLabel (New ImageIcon ("d://abc//12.jpg"));
		JLabel age = New JLabel (New ImageIcon ("d://abc//14.jpg"));
		JLabel birthday = new JLabel (New ImageIcon ("d://abc//15.jpg"));
		JLabel address = new JLabel (New ImageIcon ("d://abc//16.jpg"));
		JLabel grade = new JLabel (New ImageIcon ("d://abc//17.jpg"));
		JLabel major = new JLabel (New ImageIcon ("d://abc//18.jpg"));
		JLabel title = new JLabel (str);
		Nameinput = new JComboBox ();
		Codeinput = new JTextField (10);
		Sexyinput = new JTextField (10);
		Ageinput = new JTextField (10);
		Birthdayinput = new JTextField (10);
		Addressinput = new JTextField (10);
		Gradeinput = new JTextField (10);
		Majorinput = new JTextField (10); /extract the data stored in the vector and reassign it to the student object.
		Then use the Student object//GetName method to extract the names of the students, and finally use the Add function of the combo list box to add these names to the list.
		Vector VEC = Store.getstudent (con, SQL);
			for (int i = 0; i < vec.size (); i++) {Studentbean one = (Studentbean) vec.get (i);
			String nameselect = One.getname ();
		Nameinput.additem (NameSelect); } String Namestring = (String) nameinput.getselecteditem ();
		Studentbean p = Store.getobject (con, namestring);
		String Inputcode = P.getcode ();
		String inputsexy = P.getsexy ();
		String inputage = P.getage ();
		String inputbirthday = P.getbirthday ();
		String inputaddress = p.getaddress ();
		String Inputgrade = P.getgrade ();
		String inputmajor = P.getmajor ();
		Codeinput.settext (Inputcode);
		Sexyinput.settext (inputsexy);
		Ageinput.settext (Inputage);
		Birthdayinput.settext (Inputbirthday);
		Addressinput.settext (inputaddress);
		Gradeinput.settext (Inputgrade);
		Majorinput.settext (Inputmajor);
		JButton addition = new JButton ("Add");
		JButton Delete = new JButton ("delete");
		JButton update = new JButton ("Update");
		JButton Bereturn = new JButton ("return");
		gridbagconstraints constraints = new gridbagconstraints ();
		Constraints.fill = Gridbagconstraints.none;
		CONSTRAINTS.WEIGHTX = 4;
		Constraints.weighty = 6; Add (title, constraints, 0, 0, 4, 1);
	Add controls using the Grid group layout (name, constraints, 0, 1, 1, 1);	Add (Code, constraints, 0, 2, 1, 1);
		Add (sexy, Constraints, 0, 3, 1, 1);
		Add (age, Constraints, 0, 4, 1, 1);
		Add (Nameinput, Constraints, 1, 1, 1, 1);
		Add (Codeinput, Constraints, 1, 2, 1, 1);
		Add (Sexyinput, Constraints, 1, 3, 1, 1);
		Add (Ageinput, Constraints, 1, 4, 1, 1);
		Add (Birthday, Constraints, 2, 1, 1, 1);
		Add (Address, Constraints, 2, 2, 1, 1);
		Add (grade, Constraints, 2, 3, 1, 1);
		Add (Major, Constraints, 2, 4, 1, 1);
		Add (Birthdayinput, Constraints, 3, 1, 1, 1);
		Add (Addressinput, Constraints, 3, 2, 1, 1);
		Add (Gradeinput, Constraints, 3, 3, 1, 1);
		Add (Majorinput, Constraints, 3, 4, 1, 1);
		Add (addition, constraints, 0, 5, 1, 1);
		Add (delete, Constraints, 1, 5, 1, 1);
		Add (Update, Constraints, 2, 5, 1, 1);
		Add (Bereturn, Constraints, 3, 5, 1, 1); /by clicking on the name in each list box, all the information for that name is displayed Nameinput.additemlistener (new ItemListener () {public void itemstatechanged (ITEMEV
				Ent e) {String namestring = (string) nameinput.getselecteditem (); Studentbeanp = Store.getobject (con, namestring);
				String Inputcode = P.getcode ();
				String inputsexy = P.getsexy ();
				String inputage = P.getage ();
				String inputbirthday = P.getbirthday ();
				String inputaddress = p.getaddress ();
				String Inputgrade = P.getgrade ();
				String inputmajor = P.getmajor ();
				Codeinput.settext (Inputcode);
				Sexyinput.settext (inputsexy);
				Ageinput.settext (Inputage);
				Birthdayinput.settext (Inputbirthday);
				Addressinput.settext (inputaddress);
				Gradeinput.settext (Inputgrade);
			Majorinput.settext (Inputmajor);
		}
		}); /Return to main Menu Bereturn.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent Event) {Stud
				Entmanageframe manageframe = new Studentmanageframe ();
				Manageframe.setvisible (TRUE);
			Studentinfoframe.dispose ();
		}
		}); /Enter Add main interface Addition.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent Event) {St
				Udent_frame ADDFR = new Student_frame (); AddfR.setvisible (TRUE);
		}
		});  /Update button, which enables data extraction from the database table to be displayed in the interface Update.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent
				Event) {String name1 = Af.ss.getname ();
				String code1 = Af.ss.getcode ();
				String age1 = Af.ss.getage ();
				String sexy1 = Af.ss.getsexy ();
				String birthday1 = Af.ss.getbirthday ();
				String Address1 = af.ss.getaddress ();
				String grade1 = Af.ss.getgrade ();
				String Major1 = Af.ss.getmajor ();
				Nameinput.additem (NAME1);
				Nameinput.setselecteditem (NAME1);
				Codeinput.settext (CODE1);
				Ageinput.settext (AGE1);
				Sexyinput.settext (SEXY1);
				Addressinput.settext (ADDRESS1);
				Birthdayinput.settext (Birthday1);
				Gradeinput.settext (GRADE1);
			Majorinput.settext (Major1);
		}
		});
				/delete data and update to database Delete.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent Event) {
				String namestring = (string) nameinput.getselecteditem (); From_student store = new From_student ();
					try {Connection con = store.getconnection ();
					Statement st = Con.createstatement ();
					String sql = "Delete * from Studentinfo where= '" + namestring + "'";
				St.executeupdate (SQL);
			catch (Exception e) {} nameinput.removeitem (namestring);
	}

		});
 }
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.