Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7682297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:32:08+00:00 2026-05-31T18:32:08+00:00

First off, I’m new to Java, so please be gentle. I have a JFrame

  • 0

First off, I’m new to Java, so please be gentle.

I have a JFrame which has two ‘JPanels’, one of which is a separate class (i’ve extended the JPanel). Ideally I’d like to ‘dispatch and event’ or notify the other JPanel object on the JFrame.

I have an array of JButtons in the custom JPanel class, which i’d like to add an event listener to. Upon clicking the JButton, i’d like to change something on the other JPanel.

I’m really not sure how to do this, so I moved the event handler into the JFrame class, and tried to do the following:

panel.buttonArray[i][j].addActionListener(this);

However, doing that didn’t work at all. Annoyingly, Eclipse didn’t complain either…

Any tips on how I can achieve this?

This was horribly explained, sorry.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:32:09+00:00Added an answer on May 31, 2026 at 6:32 pm

    Think of this not in terms of panels but in terms of objects. As long an object, lets say it has a name of object77, has a reference to the other object, call it object42, object77 can call methods on object42.

      object77.methodInObject42();
    
      panel77.methodInPanel42();
    

    As for the event handler, then

       buttonOnPanelXX.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e) {
                 panel77.methodInPanel42();
           }});
    

    or even better…

        button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                SwingUtilities.invokeLater(new Runnable(){
                   public void run() {
                      panel77.methodInPanel42();
                   }});
                }});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off I'm new to Android and Java.. I have been trying to add
First off I am pretty new to C, so I probably just have a
First off, please accept my apologies if this question is basic, I mainly have
First off, I'm a real beginer at C# so please be gentle. I'm trying
First off.. I am new to asp.net and EF. I have an EntityDatsource on
First off, I am using Windows XP. I have multiple hard drives and it
First off, I apologize if this doesn't make sense. I'm new to XHTML, CSS
First off, a big thanks to the people behind the new boost::geometry library! This
First off, I will say i've spent 6 hours on this topic and have
First off, I'm pretty new so I hope I hadn't missed anything too trivial.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.