那位大哥帮下我,,需要一个JAVA记事本小程序,里面就只需要一个保存和退出功能!

解决方案 »

  1.   

    需求能在详细一点么?
    记事本界面是GUI设计还是什么?
    需要背景不?
      

  2.   

    DefaultEditorKit kit = new DefaultEditorKit();
    Document doc = jtextcomponent.getDocument();
    kit.write(new FileWriter(...), doc, 0, doc.getLength());
      

  3.   

    import javax.swing.*;
    class Benben extends JFrame{
    Benben(){
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.add(new JButton("保存"){addActionListener(this)});
    }
    public void ActionPerformed(Actionevent e)
    {
    doSave();
    }
    void doSave(){
    FileDialog fd =new  FileDialog(mf,"saveFile",FileDialog.SAVE);
    fd.setVisible(true);
    String s= fd.getDirectory();
    String fl=fd.getFile();
    String filename=s+fl;
    String str =mf.jta.getText();
    try{
    FileWriter fw = new FileWriter(filename);
    fw.write(str);
    fw.close();
    }
    catch(Exception e){}
    }
    }