You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GrafikModel.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package mvcgrafik.model;
  7. import java.awt.Point;
  8. import java.io.BufferedInputStream;
  9. import java.io.BufferedOutputStream;
  10. import java.io.FileInputStream;
  11. import java.io.FileNotFoundException;
  12. import java.io.FileOutputStream;
  13. import java.io.IOException;
  14. import java.io.ObjectInputStream;
  15. import java.io.ObjectOutputStream;
  16. import java.util.ArrayList;
  17. import java.util.Collections;
  18. import java.util.List;
  19. /**
  20. *
  21. * @author le
  22. */
  23. public class GrafikModel
  24. {
  25. private ArrayList<Point> punkte;
  26. public GrafikModel()
  27. {
  28. punkte = new ArrayList<>();
  29. }
  30. public void addPoint(Point p)
  31. {
  32. punkte.add(p);
  33. }
  34. public List<Point> getPunkte()
  35. {
  36. return Collections.unmodifiableList(punkte);
  37. }
  38. public void speicherePunkte(String dateiname) throws FileNotFoundException, IOException
  39. {
  40. FileOutputStream fos = new FileOutputStream(dateiname);
  41. BufferedOutputStream buffout = new BufferedOutputStream(fos);
  42. ObjectOutputStream oos = new ObjectOutputStream(buffout);
  43. oos.writeObject(punkte);
  44. oos.flush();
  45. oos.close();
  46. }
  47. public void ladePunkte(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException
  48. {
  49. FileInputStream fis = new FileInputStream(dateiname);
  50. BufferedInputStream buffin = new BufferedInputStream(fis);
  51. ObjectInputStream ois = new ObjectInputStream(buffin);
  52. Object obj = ois.readObject();
  53. // if (obj instanceof ArrayList)
  54. // {
  55. // punkte = (ArrayList<Point>) obj;
  56. // }
  57. // else
  58. // {
  59. // Fehler ....
  60. // }
  61. punkte = (ArrayList<Point>) ois.readObject();
  62. ois.close();
  63. }
  64. }