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.

CommandSave.java 1.4KB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 controller.commands;
  7. import model.AdressverwaltungModel;
  8. import controller.Interface;
  9. import java.io.File;
  10. import java.io.FileNotFoundException;
  11. import java.io.IOException;
  12. import javax.swing.JFileChooser;
  13. import prfourgui.Constants;
  14. import prfourgui.View.AdressbuchView;
  15. /**
  16. *
  17. * @author jechowma68968
  18. */
  19. public class CommandSave implements Interface
  20. {
  21. private final AdressbuchView view;
  22. private final AdressverwaltungModel model;
  23. public CommandSave(AdressbuchView view, AdressverwaltungModel model)
  24. {
  25. this.view = view;
  26. this.model = model;
  27. }
  28. @Override
  29. public void execute()
  30. {
  31. File datei;
  32. JFileChooser fc = view.getjFileChooser1();
  33. int wahl = fc.showOpenDialog(view);
  34. if(wahl == JFileChooser.APPROVE_OPTION){
  35. datei = fc.getSelectedFile();
  36. String dateiname = datei.getAbsolutePath();
  37. model.setPref(Constants.PREF_KEY_DIR, dateiname);
  38. view.getTxtStatus().setText("Dateipfad:" + dateiname);
  39. try{
  40. model.datenSpeichern(datei);
  41. }
  42. catch(FileNotFoundException e){
  43. System.out.println("File not Found Error");
  44. }
  45. catch(IOException e){
  46. System.out.println("Reading Error");
  47. }
  48. }
  49. }
  50. @Override
  51. public void undo()
  52. {
  53. }
  54. }