
package presentacion;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JOptionPane;

public class Controller extends WindowAdapter implements ActionListener { 

       private InterfazPrediccion interfazPrediccion;
       
    public Controller(InterfazPrediccion interfazPrediccion) {
        this.interfazPrediccion = interfazPrediccion;              
    }
      
      
           // MÉTODO DE WindowAdapter  
    public void windowClosing(WindowEvent e) { 
        centralizar("cerrarVentana");           
    }         
    
      
           // MÉTODO DE ActionListener    
    public void actionPerformed(ActionEvent e) {   

          String componenteFuente = e.getActionCommand();
          
          switch(componenteFuente)
          {                                          
              case "cargarProvincias" :                   
              case "comboProvincias":
              case "comboMunicipios":
                      centralizar(componenteFuente);                
                      break;                     
          }
    }    
    
    
    public void centralizar(String actionCommand) {
       
        try {
              switch (actionCommand)
              {     
                  case "cargarProvincias": 
                  case "comboProvincias": 
                  case "comboMunicipios":                      
                         interfazPrediccion.responderAController(actionCommand);                          
                         break;                     
                  case "cerrarVentana":
                         System.exit(0);
                         break;                              
              }                        
            } catch (Exception exception)
               {  JOptionPane.showMessageDialog(null, exception.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);  }                
    }    
}
