https://pastein.ru/t/7e

  скопируйте уникальную ссылку для отправки

Загрузка данных


public class Interface implements Serializable {
	JFrame frame;
	JTabbedPane tabs;
	JButton add;
	String fileName = "d://test.txt";

	public static void main(String[] args) throws IOException, ClassNotFoundException {
		Interface inter = new Interface();
		inter.go();
		
		try{
		ObjectInputStream input = new ObjectInputStream(new FileInputStream(inter.fileName));
		
		int size = input.readInt();
		for (int i=0;i<size;i++){
			JPanel panel = (JPanel) input.readObject();	
			inter.tabs.add(panel);
		}
		
		
		input.close();}
		catch (FileNotFoundException e1){System.out.println("go");}

	}
	
	public void go(){
		this.frame = new JFrame();
		this.tabs =  new JTabbedPane();
		this.add = new JButton("добавить");
		
		frame.add(tabs, BorderLayout.CENTER);
		frame.add(add, BorderLayout.SOUTH);
		add.addActionListener(new AddTab());
		frame.setSize(500, 400);
		frame.setResizable(true);
		frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		frame.setVisible(true);
		frame.addWindowListener(new CloseFrame());
	}
	
	public class AddTab implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			Tab tab = new Tab();
			tabs.add(tab.getTab());
			
		}
		
	}
	public class CloseFrame extends WindowAdapter{
		public void windowClosing(WindowEvent event){
			File file = new File(fileName);
			try {
				FileOutputStream writer =new FileOutputStream(file);
				String s = "";
				writer.write(s.getBytes());
				writer.close();
			} catch (FileNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
			
				ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(file,true));
				Component[] arr = tabs.getComponents();
				output.writeInt(arr.length);
				for (Component comp:arr){
					output.writeObject(comp);
				}
				output.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.exit(0);	
		}
		

	}
	
	         

}