title: The JFrame or the JPanel don't listen to the clicking event
body: <p>I have this JFrame(BorderLayout), that has 3 Jpanel in it(north, center, south).
  The center panel, has a login button.
  For testing purposes, what I want is to print &quot;hello&quot;, when pressed.</p>
  <p>This is how the frame currently looks:
  <a href="https://i.stack.imgur.com/DRvld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DRvld.png" alt="enter image description here" /></a></p>
  <p>I have tried 2 ways:</p>
  <ol>
  <li><p>&quot;implements ActionListener&quot;, on the center panel, but nothing happens, not even an error.</p>
  </li>
  <li><p>&quot;implements ActionListener&quot;, on the frame itself, however, I am having issues (more like, I don't know how to) &quot;importing&quot;/having access to the button, so the JFrame can listen to the cliking event</p>
  </li>
  </ol>
  <p>Hope you can help me.</p>
  <p>This is the code:</p>
  <p>Main program:</p>
  <pre><code>package com.system.reservation.airline;
  
  public class Main {
      public static void main(String[] args) {
          LoginPage loginPage = new LoginPage(); 
      }
  }
  </code></pre>
  <p>LoginPage:</p>
  <pre><code>import com.system.reservation.airline.panels.BodyPanel;
  import com.system.reservation.airline.panels.FooterPanel;
  import com.system.reservation.airline.panels.HeaderPanel;
  
  import javax.swing.*;
  import java.awt.*;
  
  public class LoginPage extends JFrame{ 
      HeaderPanel headerPanel = new HeaderPanel();
      BodyPanel bodyPanel = new BodyPanel();
      FooterPanel footerPanel = new FooterPanel();
  
      public LoginPage(){ // Constructor
          this.setTitle(&quot;Login&quot;);
          this.setSize(400, 600);
          this.setLocationRelativeTo(null);
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
          this.getContentPane().setBackground(new Color(240,248,255));
          this.setLayout(new GridBagLayout());
  
          GridBagConstraints gbc = new GridBagConstraints();
  
          gbc.weightx = 1;
          gbc.weighty = 1;
          gbc.fill = GridBagConstraints.BOTH;
  
          gbc.gridx = 0;
          gbc.gridy = 0;
          gbc.gridheight = 1;
          this.add(headerPanel, gbc);
  
          gbc.gridx = 0;
          gbc.gridy = 1;
          gbc.gridheight = 1;
          this.add(bodyPanel, gbc);
  
          gbc.gridx = 0;
          gbc.gridy = 2;
          gbc.gridheight = 3;
          this.add(footerPanel, gbc);
  
          this.pack();
          this.setVisible(true);
      }
  }
  </code></pre>
  <p>BodyPanel:</p>
  <pre><code>package com.system.reservation.airline.panels;
  
  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  public class BodyPanel extends JPanel implements ActionListener{
      JLabel login_label;
      JButton login_button = new JButton(&quot;Login&quot;);
      Color transparent = new Color(1f,0f,0f,0f);
  
      public BodyPanel(){
          this.setBackground(transparent);
          this.setLayout(new BorderLayout());
          this.setBorder(BorderFactory.createLineBorder(Color.green, 3));
          //------------ Login Panel ------------------------
          JPanel login_panel = new JPanel(new BorderLayout());
          login_panel.setBackground(transparent);
          login_panel.setPreferredSize(new Dimension(400, 100));
          //login_panel.setBorder(BorderFactory.createLineBorder(Color.YELLOW, 5));
  
          login_label = new JLabel();
          login_label.setText(&quot;Login&quot;);
          login_label.setHorizontalAlignment(JLabel.CENTER);
          login_label.setFont(new Font(&quot;Arial&quot;, Font.PLAIN, 20));
  
          login_panel.add(login_label, BorderLayout.NORTH);
          //------------ Login Panel ------------------------
  
          //------------ Input Panel ------------------------
          JPanel input_fields_panel = new JPanel(new GridBagLayout());
          input_fields_panel.setBackground(transparent);
          input_fields_panel.setPreferredSize(new Dimension(400, 150));
          //input_fields_panel.setBorder(BorderFactory.createLineBorder(Color.black, 5));
  
          GridBagConstraints gbc = new GridBagConstraints();
  
          gbc.weightx = 1;
          gbc.weighty = 1;
          gbc.fill = GridBagConstraints.BOTH;
  
          //-------------
          JLabel userName_label = new JLabel(&quot;Username: &quot;);
          gbc.gridx = 0;
          gbc.gridy = 0;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.insets = new Insets(0,10,0,0);
          input_fields_panel.add(userName_label, gbc);
  
          JTextField userName_txb = new JTextField();
          userName_txb.setPreferredSize(new Dimension(250,30));
          gbc.gridx = 3;
          gbc.insets = new Insets(0,0,5,20);
          input_fields_panel.add(userName_txb, gbc);
          //-------------
  
          //-------------
          JLabel password_label = new JLabel(&quot;Password: &quot;);
          gbc.gridx = 0;
          gbc.gridy = 1;
          gbc.gridwidth = 1;
          gbc.gridheight = 1;
          gbc.insets = new Insets(0,10,0,0);
          input_fields_panel.add(password_label, gbc);
  
          JTextField password_txb = new JTextField();
          password_txb.setPreferredSize(new Dimension(250,30));
          gbc.gridx = 1;
          gbc.gridy = 1;
          gbc.gridwidth = 3;
          gbc.gridheight = 1;
          gbc.insets = new Insets(5,0,5,20);
          input_fields_panel.add(password_txb, gbc);
          //-------------
  
          gbc.gridx = 0;
          gbc.gridy = 2;
          gbc.gridwidth = 4;
          gbc.gridheight = 1;
          gbc.insets = new Insets(5,150,5,150);
          input_fields_panel.add(login_button, gbc);
  
          JLabel tokenResponse = new JLabel(&quot;Username or password, are incorrect!&quot;);
          tokenResponse.setHorizontalAlignment(JLabel.CENTER);
          gbc.gridx = 0;
          gbc.gridy = 3;
          gbc.gridwidth = 4;
          gbc.gridheight = 1;
          gbc.insets = new Insets(0,0,0,0);
          input_fields_panel.add(tokenResponse, gbc);
          //------------ Input Panel ------------------------
  
          //-------------------------------------
          this.add(login_panel, BorderLayout.NORTH);
          this.add(input_fields_panel, BorderLayout.CENTER);
      }
  
      @Override
      public void actionPerformed(ActionEvent e) {
          if(e.getSource() == login_button) {
              System.out.println(&quot;Hello&quot;);
          }
      }
  }
  </code></pre>
  <p>The center panel is the BodyPanel, hence I did not include the code for the HeaderPanel, or the FooterPanel.</p>
  <p>So to recap, I want to either the LoginPage to have access or to listen to the clicking event of the login_button, or the exact same for the BodyPanel.</p>