|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
- package mvcgrafik.model;
-
- import java.awt.Point;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
-
- /**
- *
- * @author le
- */
- public class GrafikModel
- {
- private ArrayList<Point> punkte;
-
- public GrafikModel()
- {
- punkte = new ArrayList<>();
- }
-
- public void addPoint(Point p)
- {
- punkte.add(p);
- }
-
- public List<Point> getPunkte()
- {
- return Collections.unmodifiableList(punkte);
- }
-
- public void speicherePunkte(String dateiname) throws FileNotFoundException, IOException
- {
- FileOutputStream fos = new FileOutputStream(dateiname);
- BufferedOutputStream buffout = new BufferedOutputStream(fos);
- ObjectOutputStream oos = new ObjectOutputStream(buffout);
- oos.writeObject(punkte);
- oos.flush();
- oos.close();
- }
-
- public void ladePunkte(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException
- {
- FileInputStream fis = new FileInputStream(dateiname);
- BufferedInputStream buffin = new BufferedInputStream(fis);
- ObjectInputStream ois = new ObjectInputStream(buffin);
- Object obj = ois.readObject();
- // if (obj instanceof ArrayList)
- // {
- // punkte = (ArrayList<Point>) obj;
- // }
- // else
- // {
- // Fehler ....
- // }
- punkte = (ArrayList<Point>) ois.readObject();
- ois.close();
- }
-
- }
|