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 4533016
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:06:09+00:00 2026-05-21T14:06:09+00:00

This may have been asked many times before or I don’t know what to

  • 0

This may have been asked many times before or I don’t know what to search for to get an answer. What I have got is a JFrame that loads in several JPanels. What I am having difficulty in is updating the contents of one JPanel from another. So say I have the following:

JFrame1.JPanel1.JButtonA
JFrame1.JPanel2.JButtonB

When JButtonA is pressed I want JButtonB to have its text changed. Of course this isn’t what I want to do but is a simple example of what I would like to achieve. Where am I going wrong? How to get a reference to an object without making everything a singleton?

  • 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-21T14:06:09+00:00Added an answer on May 21, 2026 at 2:06 pm

    The easiest way is of course to remember a reference to JFrame1 when construction JPanel1:

    JPanel1 p1 = new JPanel1(this);
    

    and remember and use that in JPanel1:

    public JPanel1(JFrame1 f1) {
        this.f1 = f1;
    }
    ...
    public void actionPerformend(...) {
        f1.getPanel2().getButtonB().setText("A is pressed");
    }
    

    But that’s bad.

    Instead, think about what clicking A really means (for example pauze game). Then create a PauzeGameEventListener interface, implemented by JPanel2 (for example the chessboard) and make JPanel1 (for example the game controls panel) fire a PauzeGameEvent to all listeners. That way, when your JPanel3 (for example score panel) or non-gui stuff (for example the AI player) needs to be aware of that too, you’re not littering the JPanel1 code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question may have been asked before, but I had trouble finding an answer,
This may have been asked before, but I could not find the answer. I
This question may have been asked before, but I'm starting to get into game
this question may have been asked many times, but could not find any suitable
I know this question has been asked many times, but I have not been
This may have been asked before, but it's really hard to search for terms
This has / may have been asked before, but, as far as I remember,
This may have been answered before, and if so, point me to the answer.
This may have been asked before, and I have seen similar solutions... Perhaps I
Ok, I know this has been asked a thousand times before, but no conclusive

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.