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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:17:27+00:00 2026-05-28T08:17:27+00:00

Say, you have a subclass of JFrame , and use it to create your

  • 0

Say, you have a subclass of JFrame, and use it to create your own custom JFrame. In this class (we’ll call it mainFrame), we create a reference to another custom JFrame class (we’ll call this one sidePanel).

In sidePanel, you have different buttons, radio buttons,..

My question is, is there a way to notify mainFrame the user presses on a button?

I’ve created a (untested) example of what I mean:

class mainFrame extends JFrame {
   public mainFrame() {
      super("main frame");
      //...........
      sidePanel panel = new sidePanel();
      //...........
   }
   public static void main(String[] args) {
      mainFrame mainF = new mainFrame();
      //.........
   }
}

And the sidePanel class:

class sidePanel extends JFrame {

   public sidePanel() {
      super("sidePanel frame");
      //...........
      JButton button1 = new JButton();
      button1.addActionListener(new ActionListener() {  
          public void actionPerformed(ActionEvent e)
            {
               //Notify mainFrame somehow button is pressed
          }});
      //...........
    }
}
  • 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-28T08:17:28+00:00Added an answer on May 28, 2026 at 8:17 am

    To notify mainFrame of an event, the SidePanel instance (really bad name for a Frame) must have a reference to mainFrame. Pass mainFrame as an argument of the SidePanel constructor, and callback mainFrame from the actionPerformed method in SidePanel:

    SidePanel panel = new SidePanel(this);
    

    and in SidePanel:

    public void actionPerformed(ActionEvent e) {
        mainFrame.buttonHasBeenClicked();
        ...
    }
    

    This tightly couples both classes though. A way to decouple them is to make the SidePanel object accept listeners for custom events, and to fire such an event when the button is clicked. The mainFrame would construct the SidePanel instance, and add itself (or an inner anonymous class instance) as a listener to the sidePanel.

    See this page for an example.

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

Sidebar

Related Questions

Let's say I have this class and its subclass @interface MySuperClass - (void)open:(id)type value:(id)value;
Lets say have this immutable record type: public class Record { public Record(int x,
Say I have this class Myclass that contains this method: public class MyClass {
Let's say I have this class: public abstract class CustomerCollectionBase : Collection<Customer>{} One of
Say I have a class Foo, a class A and some subclass B of
Lets say i have something like this: This is file tree.py: class leaf(): def
Let's say we have this part of code for a UIView subclass: self.myImage =
I have a subclass of UITableViewCell that I create for a UITableView. Let's say
Let's say I have an abstract class called ViewController, and another abstract class called
Say I have this Class @interface CustomClass : NSObject @property (nonatomic, strong) NSArray *

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.