Advertisement
rburgosnavas

Load/Save

Dec 6th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. private void load()
  2. {
  3.     int val = jfc.showOpenDialog(DrawBoardLayoutDemo.this);
  4.     if (val == JFileChooser.APPROVE_OPTION)
  5.     {
  6.         File f = new File(jfc.getSelectedFile().getAbsolutePath());
  7.         try
  8.         {
  9.             FileInputStream fin = new FileInputStream(f.getAbsoluteFile());
  10.             ObjectInputStream ios = new ObjectInputStream(fin);
  11.             drawPanel.shape = (ArrayList<Shape>) ios.readObject();
  12.             ios.close();
  13.             fin.close();
  14.             drawPanel.repaint();
  15.             index = drawPanel.shape.size();
  16.         }
  17.         catch (FileNotFoundException e2)
  18.         {
  19.             e2.printStackTrace();
  20.         }
  21.         catch (IOException e2)
  22.         {
  23.             e2.printStackTrace();
  24.         }
  25.         catch (ClassNotFoundException e2)
  26.         {
  27.             e2.printStackTrace();
  28.         }
  29.     }
  30.     else
  31.     {
  32.         System.err.println("Nothing was loaded.");
  33.     }
  34. }
  35.  
  36. private void save()
  37. {
  38.     int val = jfc.showSaveDialog(DrawBoardLayoutDemo.this);
  39.     if (val == JFileChooser.APPROVE_OPTION)
  40.     {
  41.         File f = new File(jfc.getSelectedFile().getAbsolutePath());
  42.         try
  43.         {
  44.             FileOutputStream fout = new FileOutputStream(f.getAbsoluteFile());
  45.             ObjectOutputStream oos = new ObjectOutputStream(fout);
  46.             oos.writeObject(drawPanel.shape);
  47.             oos.flush();
  48.             oos.close();
  49.             fout.close();
  50.         }
  51.         catch (FileNotFoundException e1)
  52.         {
  53.             System.err.println("File not found");
  54.         }
  55.         catch (IOException e1)
  56.         {
  57.             System.err.println("Error loading");
  58.         }
  59.     }
  60.     else
  61.     {
  62.         System.err.println("Nothing was saved.");
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement