Swing + Hibernate 가 만 든 간단 한 학생 정보 관리 시스템

코드 만 붙 여 주세요.

     :
package com.hejianjiao.student.main;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Hashtable;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import com.hejianjiao.student.oper.Delete;
import com.hejianjiao.student.oper.Inquest;
import com.hejianjiao.student.oper.ModifySituation;
import com.hejianjiao.student.oper.StudentSituation;

public class StudentManager extends JFrame implements ActionListener {

	StudentSituation        = null;
	ModifySituation        = null;
	Inquest        = null;
	Delete        = null;

	JMenuBar bar;
	JMenu fileMenu;
	JMenuItem   ,   ,   ,   ;
	Container con = null;
	Hashtable      = null;
	// File file = null;
	CardLayout card = null;
	JLabel label = null;
	JPanel pCenter = null;

	/**
	 *    
	 * */
	public StudentManager() {
		   = new JMenuItem("        ");
		   = new JMenuItem("        ");
		   = new JMenuItem("        ");
		   = new JMenuItem("        ");

		bar = new JMenuBar();
		fileMenu = new JMenu("    ");
		fileMenu.add(  );
		fileMenu.add(  );
		fileMenu.add(  );
		fileMenu.add(  );

		bar.add(fileMenu);

		this.setJMenuBar(bar);

		label = new JLabel("            ", JLabel.CENTER);
		label.setFont(new Font("TimesRoman", Font.BOLD, 24));
		label.setForeground(Color.red);

		     = new Hashtable();
		  .addActionListener(this);
		  .addActionListener(this);
		  .addActionListener(this);
		  .addActionListener(this);

		card = new CardLayout();
		con = getContentPane();
		pCenter = new JPanel();
		pCenter.setLayout(card);
		// file = new File("    .txt");

		// if (!file.exists()) {
		// try {
		// FileOutputStream out = new FileOutputStream(file);
		// ObjectOutputStream objectOut = new ObjectOutputStream(out);
		// objectOut.writeObject(    );
		// objectOut.close();
		// out.close();
		// } catch (FileNotFoundException e) {
		// e.printStackTrace();
		// } catch (IOException e) {
		// e.printStackTrace();
		// }
		// }

		       = new StudentSituation();
		       = new ModifySituation();
		       = new Inquest(this);
		       = new Delete();

		pCenter.add("     ", label);
		pCenter.add("    ",       );
		pCenter.add("    ",       );
		pCenter.add("    ",       );
		con.add(pCenter, BorderLayout.CENTER);
		con.validate();
		this.addWindowFocusListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		setVisible(true);
		setBounds(100, 50, 420, 380);
		validate();
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() ==   ) {
			card.show(pCenter, "    ");
		} else if (e.getSource() ==   ) {
			card.show(pCenter, "    ");
		} else if (e.getSource() ==   ) {
			//                 ,         
			      .setVisible(true);
		} else if (e.getSource() ==   ) {
			card.show(pCenter, "    ");
		}
	}

	public static void main(String[] args) {
		new StudentManager();
	}

}


package com.hejianjiao.student.oper;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import com.hejianjiao.database.hibernate.StudentOper;
import com.hejianjiao.student.entity.Student;

/**
 *       
 */
public class StudentSituation extends JPanel implements ActionListener {

	// List       = null;
	JTextField   ,   ,   ,   ,   ;
	JRadioButton  ,  ;

	Student    = null;
	ButtonGroup group = null;
	JButton   ,   ;

	// FileInputStream inOne = null;
	// ObjectInputStream inTwo = null;
	// FileOutputStream outOne = null;
	// ObjectOutputStream outTwo = null;
	//
	// File file = null;

	public StudentSituation() {
		// this.file = file;
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);

		group = new ButtonGroup();

		  = new JRadioButton(" ");
		  = new JRadioButton(" ");
		group.add( );
		group.add( );

		   = new JButton("  ");
		   = new JButton("  ");

		  .addActionListener(this);
		  .addActionListener(this);
		Box box1 = Box.createHorizontalBox();//   6   Box  
		box1.add(new JLabel("  :", JLabel.CENTER));
		box1.add(  );
		Box box2 = Box.createHorizontalBox();
		box2.add(new JLabel("  :", JLabel.CENTER));
		box2.add(  );
		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(  );
		Box box5 = Box.createHorizontalBox();
		box5.add(new JLabel("  :", JLabel.CENTER));
		box5.add(  );
		Box box6 = Box.createHorizontalBox();
		box6.add(new JLabel("  :", JLabel.CENTER));
		box6.add(  );

		Box boxH = Box.createVerticalBox();//        box  ,        6   Box  

		boxH.add(box1);
		boxH.add(box2);
		boxH.add(box3);
		boxH.add(box4);
		boxH.add(box5);
		boxH.add(box6);
		boxH.add(Box.createVerticalGlue());//   box          

		JPanel pCenter = new JPanel();
		pCenter.add(boxH);
		setLayout(new BorderLayout());
		add(pCenter, BorderLayout.CENTER);
		JPanel pSourth = new JPanel();
		pSourth.add(  );
		pSourth.add(  );
		add(pSourth, BorderLayout.SOUTH);
		validate();
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() ==   ) {
			String number = "";
			number =   .getText();

			if (number.length() > 0) {
				// try {
				// inOne = new FileInputStream(file);
				// inTwo = new ObjectInputStream(inOne);
				// System.out.println("     =" +      );
				//       = (Hashtable) inTwo.readObject();//         HashTable  
				// inOne.close();
				// inTwo.close();
				// } catch (FileNotFoundException e1) {
				// e1.printStackTrace();
				// } catch (IOException e1) {
				// e1.printStackTrace();
				// } catch (ClassNotFoundException e1) {
				// e1.printStackTrace();
				// }

				StudentOper oper = new StudentOper();
				Student student = oper.getStudent(number);

				if (student != null) {//                  ,       .
					String warning = "          ,        !";
					JOptionPane.showMessageDialog(this, warning, "  ",
							JOptionPane.WARNING_MESSAGE);
				} else {
					String m = "        !";
					int ok = JOptionPane.showConfirmDialog(this, m, "  ",
							JOptionPane.YES_NO_OPTION,
							JOptionPane.INFORMATION_MESSAGE);
					if (ok == JOptionPane.YES_OPTION) {
						String name =   .getText();
						String discipling =   .getText();
						String grade =   .getText();
						String borth =   .getText();
						String sex = null;
						if ( .isSelected()) {
							sex =  .getText();
						} else {
							sex =  .getText();
						}

						   = new Student();
						  .setName(name);
						  .setId(number);
						  .setDiscipling(discipling);
						  .setBorth(borth);
						  .setSex(sex);
						  .setGrade(grade);

						//      
						boolean flag = oper.saveStudent(  );
						if (flag) {
							String success = "      !";
							JOptionPane.showMessageDialog(this, success,
									"   !", JOptionPane.OK_OPTION);
						} else {
							String fail = "      !";
							JOptionPane.showMessageDialog(this, fail, "   !",
									JOptionPane.CANCEL_OPTION);
						}

						// //             
						// try {
						// outOne = new FileOutputStream(file);
						// outTwo = new ObjectOutputStream(outOne);
						//      .put(number,   );
						// outTwo.close();
						// outOne.close();
						//   .setText(null);
						//   .setText(null);
						//   .setText(null);
						//   .setText(null);
						//   .setText(null);
						// } catch (FileNotFoundException e1) {
						// System.out.println(e1);
						// e1.printStackTrace();
						// } catch (IOException e1) {
						// System.out.println(e1);
						// e1.printStackTrace();
						// }
					}
				}
			} else {//      
				String warning = "       !";
				JOptionPane.showMessageDialog(this, warning, "  ",
						JOptionPane.WARNING_MESSAGE);
			}
		}

		if (e.getSource() ==   ) {
			  .setText(null);
			  .setText(null);
			  .setText(null);
			  .setText(null);
			  .setText(null);
		}
	}

}


package com.hejianjiao.student.oper;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import com.hejianjiao.database.hibernate.StudentOper;
import com.hejianjiao.student.entity.Student;

/**
 *       
 */
public class ModifySituation extends JPanel implements ActionListener {

	// List       = null;
	JTextField   ,   ,   ,   ,   ;
	JRadioButton  ,  ;
	ButtonGroup group = null;
	JButton     ,     ,   ;

	// FileInputStream inOne = null;
	// ObjectInputStream inTwo = null;
	// FileOutputStream outOne = null;
	// ObjectOutputStream outTwo = null;
	//
	// File file = null;

	public ModifySituation() {
		// this.file = file;
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);

		  = new JRadioButton(" ", false);
		  = new JRadioButton(" ", false);
		group = new ButtonGroup();
		group.add( );
		group.add( );

		     = new JButton("    ");
		     = new JButton("    ");
		    .setEnabled(false);

		   = new JButton("  ");

		  .addActionListener(this);
		    .addActionListener(this);
		    .addActionListener(this);
		  .addActionListener(this);

		Box box1 = Box.createHorizontalBox();//   6   Box  
		box1.add(new JLabel("          :", JLabel.CENTER));
		box1.add(  );
		box1.add(    );
		Box box2 = Box.createHorizontalBox();
		box2.add(new JLabel("( )  :", JLabel.CENTER));
		box2.add(  );
		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(  );
		Box box5 = Box.createHorizontalBox();
		box5.add(new JLabel("( )  :", JLabel.CENTER));
		box5.add(  );
		Box box6 = Box.createHorizontalBox();
		box6.add(new JLabel("( )  :", JLabel.CENTER));
		box6.add(  );

		Box boxH = Box.createVerticalBox();//        box  ,        6   Box  

		boxH.add(box1);
		boxH.add(box2);
		boxH.add(box3);
		boxH.add(box4);
		boxH.add(box5);
		boxH.add(box6);
		boxH.add(Box.createVerticalGlue());//   box          

		JPanel pCenter = new JPanel();
		pCenter.add(boxH);
		setLayout(new BorderLayout());
		add(pCenter, BorderLayout.CENTER);
		JPanel pSourth = new JPanel();
		pSourth.add(    );
		pSourth.add(  );
		add(pSourth, BorderLayout.SOUTH);
		validate();
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() ==      || e.getSource() ==   ) {
			String number =   .getText();

			if (number.length() > 0) {
				// try {
				// inOne = new FileInputStream(file);
				// inTwo = new ObjectInputStream(inOne);
				//       = (Hashtable) inTwo.readObject();//         HashTable  
				// inOne.close();
				// inTwo.close();
				// } catch (FileNotFoundException e1) {
				// e1.printStackTrace();
				// } catch (IOException e1) {
				// e1.printStackTrace();
				// } catch (ClassNotFoundException e1) {
				// e1.printStackTrace();
				// }

				StudentOper oper = new StudentOper();
				Student student = oper.getStudent(number);

				if (student != null) {//     
					    .setEnabled(true);
					Student stu = (Student) oper.getStudent(number);
					  .setText(stu.getName());
					  .setText(stu.getDiscipling());
					  .setText(stu.getGrade());
					  .setText(stu.getBorth());
					if (stu.getSex().equals(" ")) {
						 .setSelected(true);
					} else {
						 .setSelected(true);
					}
				} else {
					    .setEnabled(false);
					String m = "      !";
					JOptionPane.showMessageDialog(this, m, "  ",
							JOptionPane.WARNING_MESSAGE);

					  .setText(null);
					  .setText(null);
					  .setText(null);
					  .setText(null);
					  .setText(null);
				}
			} else {
				    .setEnabled(false);
				String m = "       !";
				JOptionPane.showMessageDialog(this, m, "  ",
						JOptionPane.WARNING_MESSAGE);
				  .setText(null);
				  .setText(null);
				  .setText(null);
				  .setText(null);
				  .setText(null);
			}
		} else if (e.getSource() ==     ) {
			String number =   .getText();

			if (number.length() > 0) {

				// try {
				// inOne = new FileInputStream(file);
				// inTwo = new ObjectInputStream(inOne);
				//       = (Hashtable) inTwo.readObject();//         HashTable  
				// inOne.close();
				// inTwo.close();
				// } catch (FileNotFoundException e1) {
				// e1.printStackTrace();
				// } catch (IOException e1) {
				// e1.printStackTrace();
				// } catch (ClassNotFoundException e1) {
				// e1.printStackTrace();
				// }

				StudentOper oper = new StudentOper();
				Student student = oper.getStudent(number);

				if (student != null) {//     
					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) {
						String name =   .getText();
						String discipling =   .getText();
						String grade =   .getText();
						String borth =   .getText();
						String sex = null;
						if ( .isSelected()) {
							sex =  .getText();
						} else {
							sex =  .getText();
						}

						Student    = new Student();
						  .setName(name);
						  .setDiscipling(discipling);
						  .setBorth(borth);
						  .setSex(sex);
						  .setGrade(grade);

						//        
						boolean flag = oper.updateStudent(  );
						if (flag) {
							String success = "      !";
							JOptionPane.showMessageDialog(this, success,
									"   !", JOptionPane.OK_OPTION);
						} else {
							String fail = "      !";
							JOptionPane.showMessageDialog(this, fail, "   !",
									JOptionPane.CANCEL_OPTION);
						}

						// //              
						// try {
						// outOne = new FileOutputStream(file);
						// outTwo = new ObjectOutputStream(outOne);
						//      .put(number,   );
						// outTwo.close();
						// outOne.close();
						//   .setText(null);
						//   .setText(null);
						//   .setText(null);
						//   .setText(null);
						//   .setText(null);
						// } catch (FileNotFoundException e1) {
						// System.out.println(e1);
						// e1.printStackTrace();
						// } catch (IOException e1) {
						// System.out.println(e1);
						// e1.printStackTrace();
						// }
						    .setEnabled(false);
					} else if (ok == JOptionPane.CANCEL_OPTION) {
						    .setEnabled(true);
					}
				} else {
					    .setEnabled(false);
					String m = "         ,    !";
					JOptionPane.showMessageDialog(this, m, "  ",
							JOptionPane.WARNING_MESSAGE);

					  .setText(null);
					  .setText(null);
					  .setText(null);
					  .setText(null);
					  .setText(null);
				}
			} else {
				    .setEnabled(false);
				String m = "       !";
				JOptionPane.showMessageDialog(this, m, "  ",
						JOptionPane.WARNING_MESSAGE);
			}
		}

		if (e.getSource() ==   ) {
			  .setText(null);
			  .setText(null);
			  .setText(null);
			  .setText(null);
			  .setText(null);
		}
	}

}


package com.hejianjiao.student.oper;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import com.hejianjiao.database.hibernate.StudentOper;
import com.hejianjiao.student.entity.Student;

/**
 *       
 */
public class Inquest extends JDialog implements ActionListener {

	// Hashtable       = null;
	JTextField   ,   ,   ,   ,   ;
	JRadioButton  ,  ;
	JButton   ;
	ButtonGroup group = null;

	// FileInputStream inOne = null;
	// ObjectInputStream inTwo = null;
	// File file = null;

	public Inquest(JFrame f) {
		super(f, "     ", false);
		// this.file = file;
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JButton("  ");

		  .addActionListener(this);
		  .addActionListener(this);

		  .setEditable(false);
		  .setEditable(false);
		  .setEditable(false);
		  .setEditable(false);

		  = new JRadioButton(" ", false);
		  = new JRadioButton(" ", false);
		group = new ButtonGroup();
		group.add( );
		group.add( );

		Box box1 = Box.createHorizontalBox();//   6   Box  ,    
		box1.add(new JLabel("        :", JLabel.CENTER));
		box1.add(  );
		box1.add(  );
		Box box2 = Box.createHorizontalBox();
		box2.add(new JLabel("  :", JLabel.CENTER));
		box2.add(  );
		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(  );
		Box box5 = Box.createHorizontalBox();
		box5.add(new JLabel("  :", JLabel.CENTER));
		box5.add(  );
		Box box6 = Box.createHorizontalBox();
		box6.add(new JLabel("  :", JLabel.CENTER));
		box6.add(  );

		Box boxH = Box.createVerticalBox();//        box  ,        6   Box  

		boxH.add(box1);
		boxH.add(box2);
		boxH.add(box3);
		boxH.add(box4);
		boxH.add(box5);
		boxH.add(box6);
		boxH.add(Box.createVerticalGlue());//   box          

		JPanel pCenter = new JPanel();
		pCenter.add(boxH);
		Container con = getContentPane();
		con.add(pCenter, BorderLayout.CENTER);
		con.validate();
		setVisible(false);
		setBounds(100, 200, 360, 270);

		this.addWindowFocusListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				setVisible(false);
			}
		});
	}

	public void actionPerformed(ActionEvent e) {
		  .setText(null);
		  .setText(null);
		  .setText(null);
		  .setText(null);

		if (e.getSource() ==    || e.getSource() ==   ) {
			String number = "";
			number =   .getText();

			if (number.length() > 0) {

				// try {
				// inOne = new FileInputStream(file);
				// inTwo = new ObjectInputStream(inOne);
				//       = (Hashtable) inTwo.readObject();//         HashTable  
				// inOne.close();
				// inTwo.close();
				// } catch (FileNotFoundException e1) {
				// e1.printStackTrace();
				// } catch (IOException e1) {
				// e1.printStackTrace();
				// } catch (ClassNotFoundException e1) {
				// e1.printStackTrace();
				// }

				StudentOper oper = new StudentOper();
				Student student = oper.getStudent(number);

				if (student != null) {//     
					  .setText(student.getName());
					  .setText(student.getDiscipling());
					  .setText(student.getGrade());
					  .setText(student.getBorth());
					if (student.getSex().equals(" ")) {
						 .setSelected(true);
					} else {
						 .setSelected(true);
					}
				} else {
					String m = "      !";
					JOptionPane.showMessageDialog(this, m, "  ",
							JOptionPane.WARNING_MESSAGE);
				}

			} else {
				String m = "       !";
				JOptionPane.showMessageDialog(this, m, "  ",
						JOptionPane.WARNING_MESSAGE);
			}
		}
	}

}


package com.hejianjiao.student.oper;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import com.hejianjiao.database.hibernate.StudentOper;
import com.hejianjiao.student.entity.Student;

/**
 *       
 * */
public class Delete extends JPanel implements ActionListener {

	// Hashtable       = null;
	JTextField   ,   ,   ,   ,   ;
	JRadioButton  ,  ;
	JButton   ;
	ButtonGroup group = null;

	// FileInputStream inOne = null;
	// ObjectInputStream inTwo = null;
	// FileOutputStream outOne = null;
	// ObjectOutputStream outTwo = null;
	//
	// File file = null;

	public Delete() {
		// this.file = file;
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);
		   = new JTextField(10);

		   = new JButton("  ");

		  .setEditable(false);
		  .setEditable(false);
		  .setEditable(false);
		  .setEditable(false);

		group = new ButtonGroup();

		  = new JRadioButton(" ");
		  = new JRadioButton(" ");
		group.add( );
		group.add( );

		  .addActionListener(this);
		  .addActionListener(this);

		Box box1 = Box.createHorizontalBox();//   6   Box  
		box1.add(new JLabel("        :", JLabel.CENTER));
		box1.add(  );
		box1.add(  );
		Box box2 = Box.createHorizontalBox();
		box2.add(new JLabel("  :", JLabel.CENTER));
		box2.add(  );
		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(  );
		Box box5 = Box.createHorizontalBox();
		box5.add(new JLabel("  :", JLabel.CENTER));
		box5.add(  );
		Box box6 = Box.createHorizontalBox();
		box6.add(new JLabel("  :", JLabel.CENTER));
		box6.add(  );

		Box boxH = Box.createVerticalBox();//        box  ,        6   Box  

		boxH.add(box1);
		boxH.add(box2);
		boxH.add(box3);
		boxH.add(box4);
		boxH.add(box5);
		boxH.add(box6);
		boxH.add(Box.createVerticalGlue());//   box          

		JPanel pCenter = new JPanel();
		pCenter.add(boxH);
		setLayout(new BorderLayout());
		add(pCenter, BorderLayout.CENTER);
		validate();
	}

	public void actionPerformed(ActionEvent e) {
		//       
		if (e.getSource() ==    || e.getSource() ==   ) {
			String number =   .getText();

			if (number.length() > 0) {
				// try {
				// inOne = new FileInputStream(file);
				// inTwo = new ObjectInputStream(inOne);
				//       = (Hashtable) inTwo.readObject();//         HashTable  
				// inOne.close();
				// inTwo.close();
				// } catch (FileNotFoundException e1) {
				// e1.printStackTrace();
				// } catch (IOException e1) {
				// e1.printStackTrace();
				// } catch (ClassNotFoundException e1) {
				// e1.printStackTrace();
				// }
				StudentOper oper = new StudentOper();
				Student student = oper.getStudent(number);

				if (student != null) {//     
					  .setText(student.getName());
					  .setText(student.getDiscipling());
					  .setText(student.getGrade());
					  .setText(student.getBorth());
					if (student.getSex().equals(" ")) {
						 .setSelected(true);
					} else {
						 .setSelected(true);
					}

					String m = "              !";
					int ok = JOptionPane.showConfirmDialog(this, m, "  ",
							JOptionPane.YES_NO_OPTION,
							JOptionPane.QUESTION_MESSAGE);
					if (ok == JOptionPane.YES_OPTION) {
						boolean flag = oper.deleteStudent(number);
						if (flag) {
							String success = "      !";
							JOptionPane.showMessageDialog(this, success,
									"   !", JOptionPane.OK_OPTION);
						} else {
							String fail = "      !";
							JOptionPane.showMessageDialog(this, fail, "   !",
									JOptionPane.CANCEL_OPTION);
						}
						// try {
						// outOne = new FileOutputStream(file);
						// outTwo = new ObjectOutputStream(outOne);
						// outOne.close();
						// outTwo.close();
						//   .setText(null);
						//   .setText(null);
						//   .setText(null);
						//   .setText(null);
						//   .setText(null);
						// } catch (FileNotFoundException e1) {
						// e1.printStackTrace();
						// } catch (IOException e1) {
						// e1.printStackTrace();
						// }

					} else if (ok == JOptionPane.NO_OPTION) {
						  .setText(null);
						  .setText(null);
						  .setText(null);
						  .setText(null);
						  .setText(null);
					}

				} else {
					//        
					String m = "      !";
					JOptionPane.showMessageDialog(this, m, "  ",
							JOptionPane.WARNING_MESSAGE);
				}
			} else {
				String m = "       !";
				JOptionPane.showMessageDialog(this, m, "  ",
						JOptionPane.WARNING_MESSAGE);
			}
		}
	}
}


package com.hejianjiao.student.entity;

/**
 *     
 * */
public class Student {

	private String id;
	private String name;
	private String discipling;//   
	private String grade;//   
	private String borth;//   
	private String sex;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDiscipling() {
		return discipling;
	}

	public void setDiscipling(String discipling) {
		this.discipling = discipling;
	}

	public String getGrade() {
		return grade;
	}

	public void setGrade(String grade) {
		this.grade = grade;
	}

	public String getBorth() {
		return borth;
	}

	public void setBorth(String borth) {
		this.borth = borth;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

}


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
 <class name="com.hejianjiao.student.entity.Student" table="student">
  <id name="id" column="id">
   <generator class="identity"/>
  </id>
  <property column="name" name="name"/>
  <property column="discipling" name="discipling"/>
  <property column="grade" name="grade"/>
  <property column="borth" name="borth"/>
  <property column="sex" name="sex"/>
 </class>
</hibernate-mapping>


package com.hejianjiao.database.hibernate;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;

import com.hejianjiao.student.entity.Student;

/**
 *      
 * */
public class StudentOper {

	public Session getCurrentSession() {
		return HibernateSessionFactory.getSession();
	}

	public void closeSession() {
		HibernateSessionFactory.closeSession();
	}

	public boolean saveStudent(Student student) {
		try {
			this.getCurrentSession().beginTransaction();
			this.getCurrentSession().save(student);
			this.getCurrentSession().beginTransaction().commit();
			return true;
		} catch (HibernateException e) {
			this.getCurrentSession().getTransaction().rollback();
			e.printStackTrace();
			return false;
		} finally {
			this.closeSession();
		}
	}

	public boolean updateStudent(Student student) {
		try {
			this.getCurrentSession().beginTransaction();
			this.getCurrentSession().update(student);
			this.getCurrentSession().beginTransaction().commit();
			return true;
		} catch (HibernateException e) {
			this.getCurrentSession().getTransaction().rollback();
			e.printStackTrace();
			return false;
		} finally {
			this.closeSession();
		}
	}

	public boolean deleteStudent(String id) {
		this.getCurrentSession().beginTransaction();
		Student student = this.getStudent(id);
		if (student != null) {
			try {
				this.getCurrentSession().delete(student);
				this.getCurrentSession().beginTransaction().commit();
				return true;
			} catch (HibernateException e) {
				this.getCurrentSession().getTransaction().rollback();
				e.printStackTrace();
			}
		}
		return false;
	}

	public Student getStudent(String id) {
		return (Student) this.getCurrentSession().get(Student.class, id);
	}

	public List getStudent() {
		List list = this.getCurrentSession().createQuery("from Student").list();
		return list;
	}
}


좋은 웹페이지 즐겨찾기