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.6KB

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