Mayday .. why do I copy other people’s code, almost exactly the same …. but why does it not save itself when I click save and then have the same file? ?

  java, question
rt java.awt.Font;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import java.io.IOException;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JPopupMenu;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
public class TextBook extends JFrame
{
    private JMenu fileMenu;//文件菜单
    private JMenuItem openItem;
    private JMenuItem saveItem;
    private JMenuItem saveAsItem;
    private JMenuItem exitItem;

    private JMenu editMenu;//编辑菜单
    private JMenuItem cutItem;
    private JMenuItem copyItem;
    private JMenuItem pasteItem;

    private JMenu styleMenu;//格式菜单
    private JMenuItem wrapItem;
    private boolean iswrap;
    private String wrap1="自动换行  ●",wrap2="自动换行  ○";
    private String wrapLabel;
    private JMenuItem FontItem;

    private JMenu aboutMenu;//关于菜单
    private JMenuItem aboutItem;

    private JMenuBar bar;//菜单栏
    private JFileChooser fileChooser;//文件选择器
    private JPopupMenu popupMenu;//右键的菜单
    private JTextArea textArea;//文本区
    private boolean isChange;//跟踪是否有所改变
    private TextBookStyleChooser tc;

    public TextBook()//初始化
    {
        super("新建文件");
        setComponent();
        setListener();
        setVisible(true);
        setSize(640,480);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public void setComponent()
    {   
        //文件菜单
        fileMenu = new JMenu("文件");
        openItem = new JMenuItem("打开");
        openItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_N,InputEvent.CTRL_MASK));
        saveItem = new JMenuItem("保存");
        saveItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_S,InputEvent.CTRL_MASK));
        saveAsItem = new JMenuItem("另存为");
        exitItem = new JMenuItem("退出");
        exitItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_O,InputEvent.CTRL_MASK));

        fileMenu.add(openItem);
        fileMenu.addSeparator();
        fileMenu.add(saveItem);
        fileMenu.add(saveAsItem);
        fileMenu.addSeparator();
        fileMenu.add(exitItem);

        //编辑菜单
        editMenu = new JMenu("编辑");
        cutItem = new JMenuItem("剪切");
        copyItem = new JMenuItem("复制");
        pasteItem = new JMenuItem("粘贴");
        cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK));
        copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
        pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK));

        editMenu.add(cutItem);
        editMenu.add(copyItem);
        editMenu.add(pasteItem);

        //格式菜单
        styleMenu = new JMenu("格式");
        wrapItem = new JMenuItem(wrapLabel);
        FontItem = new JMenuItem("字体");
        styleMenu.add(wrapItem);
        styleMenu.add(FontItem);

        //关于
        aboutMenu = new JMenu("关于");
        aboutItem = new JMenuItem("关于");
        aboutMenu.add(aboutItem);

        bar = new JMenuBar();
        bar.add(fileMenu);
        bar.add(editMenu);
        bar.add(styleMenu);
        bar.add(aboutMenu);
        setJMenuBar(bar);

        textArea = new JTextArea();
        textArea.setFont(new Font("宋体",Font.PLAIN,16));
        textArea.setLineWrap(iswrap);
        JScrollPane pane = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_NEVER,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        Container contentPane = getContentPane();
        contentPane.add(pane,BorderLayout.CENTER);
        tc=new TextBookStyleChooser();

        popupMenu = editMenu.getPopupMenu();
        fileChooser = new JFileChooser();
    }

    private void setListener()
    {
        addWindowListener(
                new WindowAdapter()
                {
                    public void windowClosing(WindowEvent e)
                    {
                        exit();
                    }
                });

        openItem.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        openFile();
                    }
                });

        saveItem.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        saveFile();
                    }
                });

        saveAsItem.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        saveAsFile();
                    }
                });

        exitItem.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        exit();
                    }
                });

        cutItem.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        cut();
                    }
                });

        copyItem.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        copy();
                    }
                });

        pasteItem.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        paste();
                    }
                });

        aboutItem.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        JOptionPane.showMessageDialog(null,"haha");
                    }
                }
                );

        textArea.addKeyListener(
                new KeyAdapter()
                {
                    public void keyTyped(KeyEvent e)
                    {
                        isChange=true;
                    }
                }
                );

        textArea.addMouseListener(
                new MouseAdapter()
                {
                    public void mouseReleased(MouseEvent e)
                    {
                        if(e.getButton()==MouseEvent.BUTTON3)
                            popupMenu.show(editMenu,e.getX(),e.getY());
                    }
                    public void mouseClicked(MouseEvent e)
                    {
                        if(e.getButton()==MouseEvent.BUTTON1)
                            popupMenu.setVisible(false);
                    }
                });

        wrapItem.addMouseListener(
                new MouseAdapter()
                {
                    public void mouseClicked(MouseEvent e)
                    {
                        if(wrapLabel==wrap1)
                        {
                            wrapLabel=wrap2;
                            iswrap=true;
                        }
                        else
                        {
                            wrapLabel=wrap1;
                            iswrap=false;
                        }
                    }
                });

        FontItem.addActionListener(
                new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        tc.setVisible(true);
                    }
                });
    }

    private void openFile()
    {
        if(isChange)
        {
            int option = JOptionPane.showConfirmDialog(null,
                    "已被修改,是否保存?","是否保存?",JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE,null);
            switch(option)
            {
            case JOptionPane.YES_OPTION:
                saveFile();
                break;
            case JOptionPane.NO_OPTION:
                open();
                break;
            }
        }
        else
            open();
    }

    private void open()
    {
        int option = fileChooser.showDialog(null, null);
        if(option == JFileChooser.APPROVE_OPTION)
        {
            try
            {
                BufferedReader buf = 
                        new BufferedReader(
                                new FileReader(
                                        fileChooser.getSelectedFile()));
                setTitle(fileChooser.getSelectedFile().toString());
                textArea.setText("");
                String text;
                isChange=false;
                String lineSeparator =System.getProperty("line.separator");
                while((text=buf.readLine())!=null)
                {
                    textArea.append(text);
                    textArea.append(lineSeparator);
                }
                buf.close();

            }catch(IOException e)
            {
                JOptionPane.showMessageDialog(null, "文件开启错误","错误",JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    public void saveFile()
    {
        File file = new File(getTitle());

        if(!file.exists())
        {
            saveAsFile();
        }
        else
        {
            try
            {
                BufferedWriter buf = 
                        new BufferedWriter(
                                new FileWriter(file));
                //将文本区写入文件
                buf.write(textArea.getText());
                buf.close();
                isChange = false;

            }catch(IOException e)
            {
                JOptionPane.showMessageDialog(null, "文件保存错误","文件保存错误",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    private void saveAsFile()
    {
        int option = fileChooser.showSaveDialog(null);

        if(option == JFileChooser.APPROVE_OPTION)
        {
            File file = fileChooser.getSelectedFile();
            setTitle(file.toString());
            try
            {
                //建立文件
                file.createNewFile();
                //选择文件保存
                saveFile();
            }catch(IOException e)
            {
                JOptionPane.showMessageDialog(null,"文件存储错误","错误",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    private void exit()
    {
        if(isChange)
        {
            int option = JOptionPane.showConfirmDialog(
                    null, "已经修改,是否保存","是否保存?",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE,null);

            switch(option)
            {
            case JOptionPane.YES_OPTION:
                saveFile();
                break;
            case JOptionPane.NO_OPTION:
                dispose();
            }
        }
        else
            dispose();
    }

    private void cut()
    {
        textArea.cut();
        isChange = true;
        popupMenu.setVisible(false);
    }

    private void copy()
    {
        textArea.copy();
        popupMenu.setVisible(false);
    }

    private void paste()
    {
        textArea.paste();
        isChange = true;
        popupMenu.setVisible(false);
    }

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

Does saving it have anything to do with how much money you copy someone else’s code? The editor is not set, is it