
package interfazgrafica6;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.event.MouseInputAdapter;

public class GestorEventos extends MouseInputAdapter implements WindowListener, ActionListener {
    
    private Componentes componentes;
    
    public GestorEventos(Componentes componentes) {
        this.componentes = componentes;
    }

         // MÉTODOS DE WindowListener  
    public void windowClosing(WindowEvent e) {
       System.exit(0);
    }    
       
    public void windowActivated(WindowEvent e) {
    }    
    
    public void windowDeactivated(WindowEvent e) {
    }        
    
    public void windowClosed(WindowEvent e) {
    }        
    
    public void windowIconified(WindowEvent e) {
    }    

    public void windowDeiconified(WindowEvent e) {
    }    

    public void windowOpened(WindowEvent e) {
    }        
    
         // MÉTODO DE ActionListener    
    public void actionPerformed(ActionEvent e) {
        JButton jButton = (JButton) e.getSource();
  
        if (jButton == componentes.getjButtonPersonalizadoContar())
         {
            int contador = componentes.getContadorPulsacionesBoton();
            contador ++;
            componentes.setContadorPulsacionesBoton(contador); 
            componentes.getjLabelVisualizaPulsacionesBoton().setText("Numero de pulsaciones botón: "+componentes.getContadorPulsacionesBoton()+"       actionCommand : "+jButton.getActionCommand()); 
         }
    }        
    
          // MÉTODOS DE MouseInputAdapter   
    public void mouseMoved(MouseEvent e) { 
       componentes.getjLabelVisualizaPosicionRaton().setText("Posicion raton:   coordenada x: "+e.getX()+"    coordenada y: "+e.getY());
    } 

   public void mousePressed(MouseEvent e) { 
      componentes.getAreaDibujo().recibirCoordenadas1(e.getX(),e.getY());
    }   

   public void mouseReleased(MouseEvent e) { 
      componentes.getAreaDibujo().recibirCoordenadas2(e.getX(),e.getY());
      componentes.getAreaDibujo().repaint();  
    }    
}
