import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*; 
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.input.*;
import org.jdom.output.*;
public class Sa1 implements ActionListener 
{
JPanel p=new JPanel();
JFrame frameobject=new JFrame("员工信息查询系统");
JButton b=new JButton("确定");
JLabel l=new JLabel("员工编号");
JTextField tf=new JTextField(10);
JLabel l1=new JLabel("姓名");
JTextField a1=new JTextField(10);
JLabel l2=new JLabel("性别");
String s[]={"男","女"};
JComboBox cb=new JComboBox(s);
String id=tf.getText();
String sex=s.toString();
String name1=a1.getText();

public void Sa1()
{
p.add(l);
p.add(tf);
p.add(l1);
p.add(a1);
p.add(l2);
p.add(cb);
p.add(b);
frameobject.getContentPane().add(p);
frameobject.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frameobject.setVisible(true);
frameobject.setSize(500,200);

b.addActionListener(this);
}
public static void main(String args[])
{
Sa1 o =new Sa1();
}
public void actionPerformed(ActionEvent evt)
{
JButton b=(JButton)evt.getSource(); XMLOutputter XMLOut = new XMLOutputter();
Element eeeRoot, eee1, eee2;
Document Doc=new Document();
eeeRoot = new Element("员工信息");
Doc = new Document(eeeRoot);
eeeRoot = Doc.getRootElement();
eee1 = new Element("员工ID");
eee2 = eee1.setText(id);
//eee2 = eee1.addAttribute("emp_id", "001");
eee1 = eeeRoot.addContent(eee2);
eee1 = new Element("员工姓名"); 
eee2 = eee1.setText("name1");
eee1 = eeeRoot.addContent(eee2);
eee1 = new Element("性别"); 
eee2 = eee1.setText("sex"); 
eee1 = eeeRoot.addContent(eee2); try{
XMLOut.output(Doc, new FileOutputStream("test1.xml"));
}
catch(Exception e1)
{
System.err.println("error:"+e1);
} }

}
运行时老是报错,希望各位提供解决方法。
qq 27258391

解决方案 »

  1.   

    无法运行 每次运行的时候说找不到MAIN 大家提示一下用JDOM 或DOM创建XML的方法。
      

  2.   

    然后在实现通过ID在XML中删除修改数据。
      

  3.   

    晕.你自己没有写 main 函数,怎么会有main 吶????
      

  4.   

    你没有main函数,你怎么走啊?
      

  5.   

    public static void main(String args[])
    {
    Sa1 o =new Sa1();
    }写了啊
      

  6.   

    java.lang.NoClassDefFoundError: org/jdom/Content
    Exception in thread "main"什么意思啊???》
      

  7.   

    java.lang.NoClassDefFoundError: org/jdom/Content
    Exception in thread "main"Content类没有,看看你的程序哪里用啦吧
      

  8.   

    java.lang.NoClassDefFoundError: org/jdom/Content
    主要是你Content这个类找不到
      

  9.   

    Content这个类找不到?这个类是做什么的???
      

  10.   

    你是不是没有争取安装jdom包呀,放一个jdom.jar 到dre的lib的extra目录里面呀
    编写的时候要把这些包正确的导入
      

  11.   

    我用的eclipse,直接把JDOM 加进去了,不是包的问题……
      

  12.   

    是包的问题,包没加进去,eclipse里有了,但程序没引用进去
      

  13.   

    pptuzi(流氓兔子♂) 你有没有看jdom的安装说明呀。
    那个上面说的jdom.jar 还要放到jre里面一份的。