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.

CommandOpen.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 adressverwaltung.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.View.AdressbuchView;
  14. /**
  15. *
  16. * @author jechowma68968
  17. */
  18. public class CommandOpen implements Interface
  19. {
  20. private final AdressbuchView view;
  21. private final AdressverwaltungModel model;
  22. public CommandOpen(AdressbuchView view, AdressverwaltungModel model)
  23. {
  24. this.view = view;
  25. this.model = model;
  26. }
  27. @Override
  28. public void execute()
  29. {
  30. File datei;
  31. JFileChooser fc = view.getjFileChooser1();
  32. int wahl = fc.showOpenDialog(view);
  33. if(wahl == JFileChooser.APPROVE_OPTION){
  34. datei = fc.getSelectedFile();
  35. String dateiname = datei.getAbsolutePath();
  36. view.getTxtStatus().setText("Dateipfad:" + dateiname);
  37. try{
  38. model.datenLesen(datei);
  39. }
  40. catch(FileNotFoundException e){
  41. System.out.println("File not Found Error");
  42. }
  43. catch(IOException e){
  44. System.out.println("Reading Error");
  45. }
  46. catch(ClassNotFoundException e){
  47. System.out.println("Class not found");
  48. }
  49. }
  50. }
  51. @Override
  52. public void undo()
  53. {
  54. }
  55. }