title: Multiple Jpanel with buttons in one Jframe on MVC, how do I get the actionlistener in my controler ?
body: <p>this is a homework btw, </p>
  
  <p>I am asked to make a jframe containing multiple jpanels which have buttons and action listeners attached to them. I have to use the MVC model to do it but, since my buttons/actions are in jpanels instead of the jframe, i do not know how to recover them. I wont put down all of my code but, just what is needed to see what I try to do. I want to get the  button "ajouter" from panel 3 first to do whatever action: </p>
  
  <p>So this is pannel 3</p>
  
  <pre><code>import java.awt.FlowLayout;
  import javax.swing.JButton;
  import javax.swing.JPanel;
  
  import ca.uqam.inf2120.tp2.modele.GestionAbsenceEmployes;
  
  public class RechercherAbsenceP3 extends JPanel {
  
      private GestionAbsenceEmployes aControleur;
      private JButton ajouter, modifier, supprimer, afficher, fermer;
      FlowLayout gestionnaireComposant;
  
      RechercherAbsenceP3() {
      try {
          jbInitP3();
      } catch (Exception e) {
          e.printStackTrace();
      }
          ajouter.addActionListener(aControleur);
          modifier.addActionListener(aControleur);
          supprimer.addActionListener(aControleur);
          afficher.addActionListener(aControleur);
          fermer.addActionListener(aControleur);
      }
  
      private void jbInitP3() throws Exception {
  
      gestionnaireComposant = new FlowLayout(FlowLayout.RIGHT);
  
      this.setLayout(gestionnaireComposant);
  
      ajouter = new JButton("Ajouter");
      modifier = new JButton("Modifier");
      modifier.setEnabled(false);
      supprimer = new JButton("Supprimer");
      supprimer.setEnabled(false);
      afficher = new JButton("Afficher");
      afficher.setEnabled(false);
      fermer = new JButton("Fermer");
  
      this.add(ajouter);
      this.add(modifier);
      this.add(supprimer);
      this.add(afficher);
      this.add(fermer);
  
      }
  
      public JButton getAjouter() {
          return ajouter;
      }
  }
  </code></pre>
  
  <p>This is the window</p>
  
  <pre><code>package ca.uqam.inf2120.tp2.interfacegraphique;
  
  import java.awt.BorderLayout;
  import ca.uqam.inf2120.tp2.interfacegraphique.RechercherAbsenceP3;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  import ca.uqam.inf2120.tp2.modele.GestionAbsenceEmployes;
  
  public class CreerRechercherAbsence extends JFrame {
  
      private GestionAbsenceEmployes aControleur;
      private JPanel absenceP1, absenceP2, absenceP3;
  
      private BorderLayout gestionnaireComposant;
  
      public CreerRechercherAbsence() {
          super("Gestionnaire des employés absents");
  
          try {
              jbInit();
          } catch (Exception ex) {
              ex.printStackTrace();
          }
  
          aControleur = new GestionAbsenceEmployes(this); 
  
      }
  
      void jbInit() throws Exception {
  
          gestionnaireComposant = new BorderLayout(5, 5);
          this.getContentPane().setLayout(gestionnaireComposant);
  
          absenceP1 = new RechercherAbsenceP1();
          absenceP2 = new RechercherAbsenceP2();
          absenceP3 = new RechercherAbsenceP3();
  
          this.getContentPane().add(absenceP1, BorderLayout.NORTH);
          this.getContentPane().add(absenceP2, BorderLayout.CENTER);
          this.getContentPane().add(absenceP3, BorderLayout.SOUTH);
      }
  
  }
  </code></pre>
  
  <p>now the not finished controler: </p>
  
  <pre><code>    package ca.uqam.inf2120.tp2.modele;
  
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
  
      import ca.uqam.inf2120.tp1.partie1.adt.impl.ListeAdtArrayListImpl;
      import ca.uqam.inf2120.tp2.interfacegraphique.CreerRechercherAbsence;
  
      public class GestionAbsenceEmployes implements ActionListener{
  
          private AbsenceEmploye modele;
          private CreerRechercherAbsence vue;
  
          public GestionAbsenceEmployes(CreerRechercherAbsence uneVue) {
              this.modele = new AbsenceEmploye();
              vue = uneVue;
          }
  
          public AbsenceEmploye getModele() {
              return modele;
          }
  
  
          @Override
          public void actionPerformed(ActionEvent event) {
              Object source = event.getSource();
              if(source == vue.getAjouter()) {
  
              }
          }
  
  }
  </code></pre>
  
  <p>When I add the vue.getAjouter() it does not know what it is !!! </p>
  
  <p>What do I do/get wrong ? </p>