Hello. Wrote code to save the text that the user writes in the text field JTextArea . When you click the Restore button, the text that was saved, but this does not happen, should be displayed. Moreover, in the Saved.ser file, the text itself is not displayed as abracadabra instead. Tell me what to do?
import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class TestSer implements Serializable { JTextArea text; public static void main(String[] args) { TestSer testSer = new TestSer(); testSer.go(); } public void go() { int width = 10; int height = 20; JFrame frame = new JFrame("Save me"); //Графическая часть JPanel panel = new JPanel(); text = new JTextArea(width, height); JButton buttonSave = new JButton("Save"); JButton buttonRestore = new JButton("Restore"); Box buttonBox = new Box(BoxLayout.Y_AXIS); frame.setSize(500,500); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(BorderLayout.NORTH, panel); frame.getContentPane().add(BorderLayout.SOUTH, buttonSave); panel.add(BorderLayout.NORTH, buttonBox); panel.add(text); buttonSave.addActionListener(new Saver()); buttonSave.addActionListener(new Restore()); buttonBox.add(buttonRestore); buttonBox.add(buttonSave); } public class Saver implements ActionListener { // Сохранение public void actionPerformed(ActionEvent a) { try { FileOutputStream fs = new FileOutputStream("Saved.ser"); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(text); os.close(); } catch(Exception ex) {ex.printStackTrace();} } } public class Restore implements ActionListener { // Загрузка public void actionPerformed(ActionEvent a) { try { FileInputStream fileStream = new FileInputStream("Saved.ser"); ObjectInputStream os = new ObjectInputStream(fileStream); Object one = os.readObject(); JTextArea text = (JTextArea) one; os.close(); } catch(Exception ex) {ex.printStackTrace();} } } }