| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package gui.simulator;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import javax.swing.JFileChooser;
- import javax.swing.JPanel;
- public class SimIo {
- public static void writeIo(JPanel panel) throws IOException
- {
- JFileChooser fileChooser = new JFileChooser();
- if(fileChooser.showSaveDialog(null)
- == fileChooser.APPROVE_OPTION) {
- java.io.File file = fileChooser.getSelectedFile();
- ObjectOutputStream output = null;
- try{
- output = new ObjectOutputStream(new FileOutputStream(file));
-
- }catch(IOException e){
- System.out.println("Could not open file." + e);
- }
- try{
-
- output.writeObject(panel);
- output.close();
- }catch(IOException e){
- System.out.println("Writing error. " + e);
- }
- }
- }
- public static SimulatorPane readIo() throws IOException
- {
- JFileChooser fileChooser = new JFileChooser();
- if(fileChooser.showOpenDialog(null)
- == fileChooser.APPROVE_OPTION) {
- java.io.File file = fileChooser.getSelectedFile();
- ObjectInputStream input = null;
- try{
- input = new ObjectInputStream(new FileInputStream(file));
- }catch(IOException e){
- System.out.println("There was a problem opening the file. " + e);
- }
- SimulatorPane pane = null;
- try{
- pane = (SimulatorPane)input.readObject();
- input.close();
- return pane;
- }catch(Exception e){
- System.out.println("There was a issue reading this file: " + e);
- }
- }
- return null;
- }
- }
|