Java implements student address book, uses XML files as data storage, and implements the functions of adding, deleting, modifying, searching, backup, restoring, professional classification searching of student numbers, names, ages, address, majors, birthdays and other information.
The project needs to import the dom4j.jar package.
/*Add student record*/import java.awt.BorderLayout;import java.awt.EventQueue;import javax.swing.ButtonGroup;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.JLabel;import javax.swing.JOptionPane;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JTextField;import javax.swing.JRadioButton;import javax.swing.JButton;import javax.swing.JComboBox;public class AddPerson extends JFrame { private JPanel contentPane; private JTextField jt1; private JTextField jt2; private JTextField jt3; private JTextField jt4; private JTextField jt5; private JTextField jt6; private JTextField jt7; public AddPerson() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 489); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(null); setContentPane(contentPane); JLabel jl1 = new JLabel("Student Address Book"); jl1.setFont(new Font("Songyi", Font.PLAIN, 16)); jl1.setBounds(10, 0, 95, 29); contentPane.add(jl1); JLabel jl2 = new JLabel("Student number"); jl2.setFont(new Font("Songyi", Font.PLAIN, 16)); jl2.setBounds(51, 39, 65, 29); contentPane.add(jl2); JLabel jl3 = new JLabel("Student name"); jl3.setFont(new Font("Songyi", Font.PLAIN, 16)); jl3.setBounds(51, 78, 65, 29); contentPane.add(jl3); JLabel jl4 = new JLabel("Student Gender"); jl4.setFont(new Font("Songyi", Font.PLAIN, 16)); jl4.setBounds(51, 117, 65, 29); contentPane.add(jl4); JLabel jl5 = new JLabel("Student Age"); jl5.setFont(new Font("Songyi", Font.PLAIN, 16)); jl5.setBounds(51, 163, 65, 29); contentPane.add(jl5); JLabel jl6 = new JLabel("Date of Birth"); jl6.setFont(new Font("宋体", Font.PLAIN, 16)); jl6.setBounds(51, 202, 65, 29); contentPane.add(jl6); JLabel jl7 = new JLabel("宋体"); jl7.setFont(new Font("宋体", Font.PLAIN, 16)); jl7.setBounds(51, 250, 65, 29); contentPane.add(jl7); JLabel jl8 = new JLabel("Email"); jl8.setFont(new Font("Zongyi", Font.PLAIN, 16)); jl8.setBounds(51, 296, 65, 29); contentPane.add(jl8); JLabel jl9 = new JLabel("Home Address"); jl9.setFont(new Font("Zongyi", Font.PLAIN, 16)); jl9.setBounds(51, 345, 65, 29); contentPane.add(jl9); JLabel jl9 = new JLabel("Home Address"); jl9.setFont(new Font("Zongyi", Font.PLAIN, 16)); jl9.setBounds(51, 345, 65, 29); contentPane.add(jl9); JLabel jl10 = new JLabel("Professional name"); jl10.setFont(new Font("宋体", Font.PLAIN, 16)); jl10.setBounds(51, 389, 65, 29); contentPane.add(jl10); jt1 = new JTextField(); jt1.setBounds(129, 38, 150, 34); contentPane.add(jt1); jt1.setColumns(10); jt2 = new JTextField(); jt2.setColumns(10); jt2.setBounds(129, 83, 150, 34); contentPane.add(jt2); jt3 = new JTextField(); jt3.setColumns(10); jt3.setBounds(129, 163, 150, 34); contentPane.add(jt3); jt4 = new JTextField(); jt4.setColumns(10); jt4.setBounds(129, 201, 150, 34); contentPane.add(jt4); jt5 = new JTextField(); jt5.setColumns(10); jt5.setBounds(129, 250, 150, 34); contentPane.add(jt5); jt6 = new JTextField(); jt6.setColumns(10); jt6.setBounds(129, 301, 150, 34); contentPane.add(jt6); jt7 = new JTextField(); jt7.setColumns(10); jt7.setBounds(129, 350, 150, 34); contentPane.add(jt7); JRadioButton radioButton = new JRadioButton("Male",true); radioButton.setBounds(139, 121, 65, 23); contentPane.add(radioButton); JRadioButton radioButton_1 = new JRadioButton("Female"); radioButton_1.setBounds(221, 121, 121, 23); contentPane.add(radioButton_1); ButtonGroup bb=new ButtonGroup(); bb.add(radioButton);bb.add(radioButton_1);JButton jb1 = new JButton("Add");jb1.setFont(new Font("Zongyi", Font.PLAIN, 16));jb1.setBounds(314, 78, 110, 61);contentPane.add(jb1);JButton jb2 = new JButton("Close");jb2.setFont(new Font("Zongyi", Font.PLAIN, 16));jb2.setBounds(314, 167, 110, 61);contentPane.add(jb2);JButton jb3 = new JButton("Clear");jb3.setFont(new Font("Zongyi", Font.PLAIN, 16));jb3.setBounds(314, 265, 110, 61);contentPane.add(jb3);String str1[]= {"Computer Science and Technology","Information Security","Electronic Information Science and Technology","Network Engineering"};JComboBox comboBox=new JComboBox(str1); ;comboBox.setBounds(126, 400, 155, 29);contentPane.add(comboBox); jb1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { PersonOperatorDome ppp=new PersonOperatorDome(); if(ppp.SerachPersonbool(jt1.getText())) { JOptionPane.showMessageDialog(null, "This ID already exists, please do not add it repeatedly"); } else { Person pp=new Person(); PersonOperatorDome person=new PersonOperatorDome(); String sex; if(radioButton.isSelected()) { sex=radioButton.getText(); } else { sex=radioButton_1.getText(); } pp.setId(jt1.getText()); pp.setName(jt2.getText()); pp.setSex(sex); pp.setBirthday(jt4.getText()); pp.setAge(jt3.getText()); pp.setPhone(jt5.getText()); pp.setEmail(jt6.getText()); pp.setAddress(jt7.getText()); pp.setMajor(String.valueOf(comboBox.getSelectedItem())); person.addPerson(pp); JOptionPane.showMessageDialog(null, "Added Success"); } }}); jb3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub jt1.setText(""); jt2.setText(""); jt3.setText(""); jt4.setText(""); jt5.setText(""); jt6.setText(""); jt7.setText(""); } }); jb2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub dispose(); } }); }} /*Person information class*/public class Person { private String id; private String name; private String sex; private String age; private String birthday; private String phone; private String email; private String address; private String major; 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 getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public String getBirthday() { return birthday; } public void setBirthday(String birthday) { this.birthday = birthday; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; }} /*Person operation interface*/import org.dom4j.Document;public interface PersonOperator { public void addPerson(Person person); public void updatePerson(Person person); public void deletePerson(String id); public Person SerachPerson(String id); public boolean SerachPersonbool(String id); public void beifen(); public void huifu();} import java.io.File;import java.io.FileOutputStream;import java.util.Iterator;import java.util.List;import org.dom4j.Document;import org.dom4j.DocumentHelper;import org.dom4j.Element;import org.dom4j.io.OutputFormat;import org.dom4j.io.SAXReader;import org.dom4j.io.XMLWriter;public class PersonOperatorDome { public void addPerson(Person person) { try { File file = new File("E:/person.xml"); Document doc = null; Element rootElem = null; if(!file.exists()) { doc = DocumentHelper.createDocument(); rootElem = doc.addElement("personlist"); } else { doc = new SAXReader().read(file); rootElem = doc.getRootElement(); } Element personElem = rootElem.addElement("person"); personElem.addAttribute("id", person.getId()); personElem.addElement("name").setText(person.getName()); personElem.addElement("sex").setText(person.getSex()); personElem.addElement("age").setText(person.getAge()); personElem.addElement("birthday").setText(person.getBirthday()); personElem.addElement("phone").setText(person.getPhone()); personElem.addElement("phone").setText(person.getPhone()); personElem.addElement("phone").setText(person.getPhone()); personElem.addElement("email").setText(person.getEmail()); personElem.addElement("address").setText(person.getAddress()); personElem.addElement("major").setText(person.getMajor()); XML.Writexml(doc); } catch (Exception e) { e.printStackTrace(); } } public void UpdatePerson(Person person) { Document doc = XML.getDocument(); Element root=doc.getRootElement(); List persons=root.elements(); for(int i=0;i<persons.size();i++) { Element test=(Element)persons.get(i); if(person.getId().equals(test.attributeValue("id"))) { for(Iterator it =test.elementIterator();it.hasNext();) { Element node=(Element)it.next(); String type=node.getName(); if("name".equals(type)) { node.setText(person.getName()); } if("sex".equals(type)) { node.setText(person.getSex()); } if("age".equals(type)) { node.setText(person.getAge()); } if("birthday".equals(type)) { node.setText(person.getBirthday()); } if("phone".equals(type)) { node.setText(person.getPhone()); } if("email".equals(type)) { node.setText(person.getEmail()); } if("address".equals(type)) { node.setText(person.getAddress()); } if("major".equals(type)) { node.setText(person.getMajor()); } } } } XML.Writexml(doc); } public void beifen() { Document doc1 = XML.getDocument(); try { File file = new File("E:/persondome.xml"); Document doc = null; Element rootElem = null; if(!file.exists()) { doc = DocumentHelper.createDocument(); rootElem = doc.addElement("personlist"); } else { doc = new SAXReader().read(file); rootElem = doc.getRootElement(); } }catch (Exception e) { e.printStackTrace(); } try { //3. Write Document to XML file FileOutputStream out = new FileOutputStream("e:/persondome.xml"); //Writing format (beautiful format) OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-8"); XMLWriter writer = new XMLWriter(out,format); writer.write(doc1); writer.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } public void huifu() { Document doc1 = XML.getDocument1(); try { FileOutputStream out = new FileOutputStream("e:/person.xml"); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-8"); XMLWriter writer = new XMLWriter(out,format); writer.write(doc1); writer.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } public void deletePerson(String id) { Document doc = XML.getDocument(); Element root=doc.getRootElement(); List persons=root.elements(); for(int i=0;i<persons.size();i++) { Element test =(Element)persons.get(i); if(id.equals(test.attributeValue("id"))) { test.detach(); break; } } XML.Writexml(doc); } public boolean SerachPersonbool(String id) { Document doc = XML.getDocument(); Element root=doc.getRootElement(); List persons=root.elements(); Person person=new Person(); for(int i=0;i<persons.size();i++) { Element test =(Element)persons.get(i); if(id.equals(test.attributeValue("id"))) { return true; } } return false; } public Person SerachPerson(String id) { Document doc = XML.getDocument(); Element root=doc.getRootElement(); List persons=root.elements(); Person person=new Person(); for(int i=0;i<persons.size();i++) { Element test =(Element)persons.get(i); if(id.equals(test.attributeValue("id"))) { for(Iterator it =test.elementIterator();it.hasNext();) { Element node=(Element)it.next(); String type=node.getName(); if("name".equals(type)) { person.setName(node.getText()); } if("sex".equals(type)) { person.setSex(node.getText()); } if("age".equals(type)) { person.setAge(node.getText()); } if("birthday".equals(type)) { person.setBirthday(node.getText()); } if("phone".equals(type)) { person.setEmail(node.getText()); } if("phone".equals(type)) { person.setEmail(node.getText()); } if("address".equals(type)) { person.setAddress(node.getText()); } if("major".equals(type)) { person.setMajor(node.getText()); } } } } return person; }} /*Find */import java.awt.BorderLayout;import java.awt.EventQueue;import javax.swing.ButtonGroup;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.JLabel;import javax.swing.JOptionPane;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JTextField;import javax.swing.JRadioButton;import javax.swing.JButton;import javax.swing.JComboBox;public class SerachPerson extends JFrame { private JPanel contentPane; private JTextField jt1; private JTextField jt2; private JTextField jt3; private JTextField jt4; private JTextField jt5; private JTextField jt6; private JTextField jt7; public SerachPerson() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 489); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(null); setContentPane(contentPane); JLabel jl1 = new JLabel("Student Address Book"); jl1.setFont(new Font("Songyi", Font.PLAIN, 16)); jl1.setBounds(10, 0, 95, 29); contentPane.add(jl1); JLabel jl2 = new JLabel("Student number"); jl2.setFont(new Font("Songyi", Font.PLAIN, 16)); jl2.setBounds(51, 39, 65, 29); contentPane.add(jl2); JLabel jl3 = new JLabel("Student name"); jl3.setFont(new Font("Songyi", Font.PLAIN, 16)); jl3.setBounds(51, 78, 65, 29); contentPane.add(jl3); JLabel jl4 = new JLabel("Student Gender"); jl4.setFont(new Font("Songyi", Font.PLAIN, 16)); jl4.setBounds(51, 117, 65, 29); contentPane.add(jl4); JLabel jl5 = new JLabel("Student Age"); jl5.setFont(new Font("Songyi", Font.PLAIN, 16)); jl5.setBounds(51, 163, 65, 29); contentPane.add(jl5); JLabel jl6 = new JLabel("Date of Birth"); jl6.setFont(new Font("宋体", Font.PLAIN, 16)); jl6.setBounds(51, 202, 65, 29); contentPane.add(jl6); JLabel jl7 = new JLabel("宋体"); jl7.setFont(new Font("宋体", Font.PLAIN, 16)); jl7.setBounds(51, 250, 65, 29); contentPane.add(jl7); JLabel jl8 = new JLabel("Email"); jl8.setFont(new Font("Zongyi", Font.PLAIN, 16)); jl8.setBounds(51, 296, 65, 29); contentPane.add(jl8); JLabel jl9 = new JLabel("Home Address"); jl9.setFont(new Font("Zongyi", Font.PLAIN, 16)); jl9.setBounds(51, 345, 65, 29); contentPane.add(jl9); JLabel jl9 = new JLabel("Home Address"); jl9.setFont(new Font("Zongyi", Font.PLAIN, 16)); jl9.setBounds(51, 345, 65, 29); contentPane.add(jl9); JLabel jl10 = new JLabel("Professional name"); jl10.setFont(new Font("宋体", Font.PLAIN, 16)); jl10.setBounds(51, 389, 65, 29); contentPane.add(jl10); jt1 = new JTextField(); jt1.setBounds(129, 38, 150, 34); contentPane.add(jt1); jt1.setColumns(10); jt2 = new JTextField(); jt2.setColumns(10); jt2.setBounds(129, 83, 150, 34); contentPane.add(jt2); jt3 = new JTextField(); jt3.setColumns(10); jt3.setBounds(129, 163, 150, 34); contentPane.add(jt3); jt4 = new JTextField(); jt4.setColumns(10); jt4.setBounds(129, 201, 150, 34); contentPane.add(jt4); jt5 = new JTextField(); jt5.setColumns(10); jt5.setBounds(129, 250, 150, 34); contentPane.add(jt5); jt6 = new JTextField(); jt6.setColumns(10); jt6.setBounds(129, 301, 150, 34); contentPane.add(jt6); jt7 = new JTextField(); jt7.setColumns(10); jt7.setBounds(129, 350, 150, 34); contentPane.add(jt7); JRadioButton radioButton = new JRadioButton("Male",true); radioButton.setBounds(139, 121, 65, 23); contentPane.add(radioButton); JRadioButton radioButton_1 = new JRadioButton("Female"); radioButton_1.setBounds(221, 121, 79, 23); contentPane.add(radioButton_1); ButtonGroup bb=new ButtonGroup(); bb.add(radioButton);bb.add(radioButton_1);JButton jb1 = new JButton("Find");jb1.setFont(new Font("宋体", Font.PLAIN, 16));jb1.setBounds(314, 78, 110, 61);contentPane.add(jb1);JButton jb2 = new JButton("宋体");jb2.setFont(new Font("宋体", Font.PLAIN, 16));jb2.setBounds(314, 280, 110, 61);contentPane.add(jb2);JButton jb3 = new JButton("Clear");jb3.setFont(new Font("Chengyi", Font.PLAIN, 16));jb3.setBounds(314, 357, 110, 61);contentPane.add(jb3);JButton jb4 = new JButton("Modify");jb4.setFont(new Font("Chengyi", Font.PLAIN, 16));jb4.setBounds(314, 174, 110, 61);contentPane.add(jb4);String str1[]= {"Computer Science and Technology","Information Security","Electronic Information Science and Technology","Network Engineering"};JComboBox comboBox = new JComboBox(str1);comboBox.setBounds(126, 394, 153, 29);contentPane.add(comboBox); jb1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { PersonOperatorDome person=new PersonOperatorDome(); String id=jt1.getText(); Person pp=person.SerachPerson(id); jt2.setText(pp.getName()); if(radioButton.getText().equals(pp.getSex())) { radioButton.setSelected(true); }else { radioButton_1.setSelected(true); } jt3.setText(pp.getAge()); jt4.setText(pp.getBirthday()); jt5.setText(pp.getPhone()); jt6.setText(pp.getEmail()); jt7.setText(pp.getAddress()); if(pp.getMajor().equals("Computer Science and Technology")) comboBox.setSelectedIndex(0); if(pp.getMajor().equals("Information Security")) comboBox.setSelectedIndex(1); if(pp.getMajor().equals("Electronic Information Science and Technology")) comboBox.setSelectedIndex(2); if(pp.getMajor().equals("Network Engineering")) comboBox.setSelectedIndex(3); } }); jb3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub jt1.setText(""); jt2.setText(""); jt3.setText(""); jt4.setText(""); jt5.setText(""); jt6.setText(""); jt7.setText(""); } }); jb2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub dispose(); } }); jb4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Person pp=new Person(); PersonOperatorDome person=new PersonOperatorDome(); String sex; if(radioButton.isSelected()) { sex=radioButton.getText(); } else { sex=radioButton_1.getText(); } pp.setId(jt1.getText()); pp.setName(jt2.getText()); pp.setSex(sex); pp.setBirthday(jt4.getText()); pp.setAge(jt3.getText()); pp.setPhone(jt5.getText()); pp.setEmail(jt6.getText()); pp.setAddress(jt7.getText()); pp.setMajor(String.valueOf(comboBox.getSelectedItem())); person.UpdataPerson(pp); JOptionPane.showMessageDialog(null, "Modified successfully"); }}); }} import java.io.File;import java.io.FileOutputStream;import org.dom4j.Document;import org.dom4j.io.OutputFormat;import org.dom4j.io.SAXReader;import org.dom4j.io.XMLWriter;public class XML { public static Document getDocument() { try { Document doc = new SAXReader().read(new File("e:/person.xml")); return doc; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } public static Document getDocument1() { try { Document doc = new SAXReader().read(new File("e:/persondome.xml")); return doc; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } /* * Write out XML file*/ public static void Writexml(Document doc) { try { //3. Write Document to XML file FileOutputStream out = new FileOutputStream("e:/person.xml"); //Writing format (beautiful format) OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("utf-8"); XMLWriter writer = new XMLWriter(out,format); writer.write(doc); writer.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } } import java.awt.BorderLayout;import java.awt.EventQueue;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.ButtonGroup;import javax.swing.JButton;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.List;import javax.swing.JTextArea;import javax.swing.JScrollBar;import javax.swing.JScrollPane;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JRadioButton;import javax.swing.JTable;import javax.swing.table.DefaultTableModel;import org.dom4j.Document;import org.dom4j.Element;public class MainContral extends JFrame { private JPanel contentPane; private JTable table; public MainContral() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 1200, 392); contentPane = new JPanel(); contentPane.setLayout(null); setContentPane(contentPane); JButton jb1 = new JButton("Add"); jb1.setFont(new Font("Zongyi", Font.PLAIN, 16)); jb1.setBounds(23, 10, 101, 48); contentPane.add(jb1); JButton jb3 = new JButton("Delete"); jb3.setFont(new Font("宋体", Font.PLAIN, 16)); jb3.setBounds(134, 10, 101, 48); contentPane.add(jb3); JButton jb4 = new JButton("/u67E5/u627E/u4E0E/u4FEE/u6539"); jb4.setFont(new Font("宋体", Font.PLAIN, 16)); jb4.setBounds(245, 10, 139, 48); contentPane.add(jb4); JButton jb5 = new JButton("Show all"); jb5.setFont(new Font("Songyi", Font.PLAIN, 16)); jb5.setBounds(394, 10, 126, 48); contentPane.add(jb5); JRadioButton radioButton = new JRadioButton("Computer Science and Technology"); radioButton.setFont(new Font("Songyi", Font.PLAIN, 16)); radioButton.setBounds(23, 89, 161, 23); contentPane.add(radioButton); JRadioButton radioButton_1 = new JRadioButton("Information Security"); radioButton_1.setFont(new Font("Zongyi", Font.PLAIN, 16)); radioButton_1.setBounds(186, 89, 101, 23); contentPane.add(radioButton_1); JRadioButton radioButton_2 = new JRadioButton("Electronic Information Science and Technology"); radioButton_2.setFont(new Font("Zongyi", Font.PLAIN, 16)); radioButton_2.setBounds(289, 89, 174, 23); contentPane.add(radioButton_2); JRadioButton radioButton_3 = new JRadioButton("Network Engineering"); radioButton_3.setFont(new Font("Zongyi", Font.PLAIN, 16)); radioButton_3.setBounds(465, 89, 101, 23); contentPane.add(radioButton_3); JRadioButton radioButton_4 = new JRadioButton("All"); radioButton_4.setFont(new Font("宋体", Font.PLAIN, 16)); radioButton_4.setBounds(568, 89, 121, 23); contentPane.add(radioButton_4); ButtonGroup bb=new ButtonGroup(); bb.add(radioButton); bb.add(radioButton_3); bb.add(radioButton_2); bb.add(radioButton_1); bb.add(radioButton_4); table = new JTable(); table.setFont(new Font("宋体", Font.PLAIN, 16)); table.setModel(new DefaultTableModel( new Object[][] { }, new String[] { "/u7F16/u53F7", "/u59D3/u540D", "/u6027/u522B", "/u5E74/u9F84", "/u751F/u65E5", "/u7535/u8BDD", "/u90AE/u7BB1", "/u5730/u5740", "/u4E13/u4E1A" } )); DefaultTableModel model = (DefaultTableModel) table.getModel(); Object[] rowData= {"number","name","gender","age","birthday","phone","email","addRow(rowData); //JScrollPane scroll = new JScrollPane(table); table.setBounds(23, 131, 1100, 212); contentPane.add(table); JButton jb6 = new JButton("Backup"); jb6.setFont(new Font("宋体", Font.PLAIN, 16)); jb6.setBounds(530, 10, 101, 48); contentPane.add(jb6); JButton jb7 = new JButton("Recover"); jb7.setFont(new Font("宋体", Font.PLAIN, 16)); jb7.setBounds(641, 10, 101, 48); contentPane.add(jb7); jb6.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub PersonOperatorDome p=new PersonOperatorDome(); p.beifen(); JOptionPane.showMessageDialog(null, "Backup Success"); } }); jb7.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub PersonOperatorDome p=new PersonOperatorDome(); p.huifu(); JOptionPane.showMessageDialog(null, "Recovery Success"); } }); jb1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub AddPerson test=new AddPerson(); test.setVisible(true); } }); jb3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub int count1=table.getSelectedRow(); String id= table.getValueAt(count1, 0).toString(); PersonOperatorDome p=new PersonOperatorDome(); p.deletePerson(id); JOptionPane.showMessageDialog(null, "Delete Successfully"); } }); jb4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub SerachPerson test=new SerachPerson(); test.setVisible(true); } }); jb5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub PersonOperatorDome person=new PersonOperatorDome(); Document doc = XML.getDocument(); Element root=doc.getRootElement(); List persons=root.elements(); DefaultTableModel model = (DefaultTableModel) table.getModel(); while(model.getRowCount()>1){ model.removeRow(model.getRowCount()-1); } for(int i=0;i<persons.size(); i++) { Element test=(Element)persons.get(i); Person person1=new Person(); person1.setId(test.attributeValue("id")); person1.setName(test.elementText("name")); person1.setSex(test.elementText("sex")); person1.setAge(test.elementText("age")); person1.setPhone(test.elementText("phone")); person1.setEmail(test.elementText("email")); person1.setBirthday(test.elementText("birthday")); person1.setBirthday(test.elementText("birthday")); person1.setAddress(test.elementText("address")); person1.setMajor(test.elementText("major")); Object[] rowData = {person1.getId(), person1.getName(), person1.getSex(), person1.getAge(), person1.getBirthday(), person1.getPhone(), person1.getEmail(), person1.getAddress(), person1.getMajor()}; model.addRow(rowData); } radioButton_4.setSelected(true); } }); radioButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Document doc = XML.getDocument(); Element root=doc.getRootElement(); List persons=root.elements(); String str=radioButton.getText(); Person person1=new Person(); DefaultTableModel model = (DefaultTableModel) table.getModel(); while(model.getRowCount()>1){ model.removeRow(model.getRowCount()-1); } for(int i=0;i<persons.size();i++) { Element test =(Element)persons.get(i); if(str.equals(test.element("major").getText())) { person1.setId(test.attributeValue("id")); person1.setName(test.elementText("name")); person1.setSex(test.elementText("sex")); person1.setAge(test.elementText("age")); person1.setPhone(test.elementText("phone")); person1.setEmail(test.elementText("email")); person1.setBirthday(test.elementText("birthday")); person1.setAddress(test.elementText("address")); person1.setMajor(test.elementText("major")); person1.setBirthday(test.elementText("birthday")); person1.setAddress(test.elementText("address")); person1.setMajor(test.elementText("major")); Object[] rowData = {person1.getId(), person1.getName(), person1.getSex(), person1.getAge(), person1.getBirthday(), person1.getPhone(), person1.getEmail(), person1.getAddress(), person1.getMajor()}; model.addRow(rowData); } } } } }); radioButton_1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Document doc = XML.getDocument(); Element root=doc.getRootElement(); List persons=root.elements(); String str=radioButton_1.getText(); Person person1=new Person(); DefaultTableModel model = (DefaultTableModel) table.getModel(); while(model.getRowCount()>1){ model.removeRow(model.getRowCount()-1); } for(int i=0;i<persons.size();i++) { Element test =(Element)persons.get(i); if(str.equals(test.element("major").getText())) { person1.setId(test.attributeValue("id")); person1.setName(test.elementText("name")); person1.setSex(test.elementText("sex")); person1.setAge(test.elementText("age")); person1.setPhone(test.elementText("phone")); person1.setPhone(test.elementText("phone")); person1.setEmail(test.elementText("email")); person1.setBirthday(test.elementText("birthday")); person1.setAddress(test.elementText("address")); person1.setMajor(test.elementText("major")); Object[] rowData = {person1.getId(), person1.getName(), person1.getSex(), person1.getAge(), person1.getBirthday(), person1.getPhone(), person1.getEmail(), person1.getAddress(), person1.getMajor()}; model.addRow(rowData); } } } }); radioButton_2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Document doc = XML.getDocument(); Element root=doc.getRootElement(); List persons=root.elements(); String str=radioButton_2.getText(); Person person1=new Person(); DefaultTableModel model = (DefaultTableModel) table.getModel(); while(model.getRowCount()>1){ model.removeRow(model.getRowCount()-1); } for(int i=0;i<persons.size();i++) { Element test =(Element)persons.get(i); if(str.equals(test.element("major").getText())) { person1.setId(test.attributeValue("id")); person1.setName(test.elementText("name")); person1.setSex(test.elementText("sex")); person1.setAge(test.elementText("age")); person1.setPhone(test.elementText("phone")); person1.setEmail(test.elementText("email")); person1.setBirthday(test.elementText("birthday")); person1.setAddress(test.elementText("address")); person1.setAddress(test.elementText("address")); person1.setMajor(test.elementText("major")); Object[] rowData = {person1.getId(), person1.getName(), person1.getSex(), person1.getAge(), person1.getBirthday(), person1.getPhone(), person1.getEmail(), person1.getAddress(), person1.getMajor()}; model.addRow(rowData); } } } }); radioButton_3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Document doc = XML.getDocument(); Element root=doc.getRootElement(); List persons=root.elements(); String str=radioButton_3.getText(); Person person1=new Person(); DefaultTableModel model = (DefaultTableModel) table.getModel(); while(model.getRowCount()>1){ model.removeRow(model.getRowCount()-1); } for(int i=0;i<persons.size();i++) { Element test =(Element)persons.get(i); if(str.equals(test.element("major").getText())) { person1.setId(test.attributeValue("id")); person1.setName(test.elementText("name")); person1.setSex(test.elementText("sex")); person1.setAge(test.elementText("age")); person1.setAge(test.elementText("age")); person1.setPhone(test.elementText("phone")); person1.setEmail(test.elementText("email")); person1.setBirthday(test.elementText("birthday")); person1.setAddress(test.elementText("address")); person1.setMajor(test.elementText("major")); Object[] rowData = {person1.getId(), person1.getName(), person1.getSex(), person1.getAge(), person1.getBirthday(), person1.getPhone(), person1.getEmail(), person1.getAddress(), person1.getMajor()}; model.addRow(rowData); } } } }); } public static void main(String[] args) { MainContral test1=new MainContral(); test1.setVisible(true); }}The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.