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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:09:22+00:00 2026-06-06T21:09:22+00:00

I am extremely confused as to how a JButton works. I have read over

  • 0

I am extremely confused as to how a JButton works. I have read over the oracle documents of the JButton, but I have failed to see how a JButton can have an actionlistener added to it. I have really always wondered how things like JFrames and all that can have things like .addMouseListener and all that. Can anyone explain how a JButton can have an actionListener added to it like the .addActionListener(...) syntax?

My reason for wanting to know how to do this is to create my own “JButton” per say which can have an actionListener added to it and it will fire events when needed. Is this even possible or no?

  • 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-06-06T21:09:23+00:00Added an answer on June 6, 2026 at 9:09 pm

    Here is what you have to do to understand the architecture. First the Design pattern used here is the Observer Pattern –

    Implementing the Publisher/Subscriber scenario. We need a mechanism
    which allows us to notify subscriber objects whenever the publisher
    object changes state.

    You can find more information about implementing it at here.

    But if your objective is to make your own JButton the best approach is to Subclass JButton.

    class MyCustomButton extends JButton{}
    

    You asked about how JFrame can have addMouseListener – It’s because JFrame extends java.awt.Component. Hope this helps.

    EDIT

    Observer doesn’t do anything. Subject notify the Observers if anything change. This is the notify method.

     public void notify()
          {
            for (int i=0;i < observers.size();i++)
            {
              Observer ob = (Observer)observers.get(i);
              ob.update(newValue);
            }
          }
    

    Back again to the Packet and the Bucket example –
    Packet – Observer
    Bucket – Subject

    Bucket wires the Packet that a new Packet has entered the Bucket. In classes Bucket class will call the notify method and all the registered Packets will be notified. If a Packet wishes to unsubscribe itself from the Bucket it just needs to call the Unsubscribe method and it will remove the Object from the ArrayList of the Bucket.

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

Sidebar

Related Questions

Getting extremely confused with an adminhtml module i'm trying to write! Effectively I have
This may be an extremely easy question but I can't get my head around
This has gotten me extremely confused. I have one scroll views on a page
I'm losing it here.. I am now extremely confused about how this loop works.
I am very new and extremely confused as to how I can accomplish this
I have an extremely simple page that I'm trying to view in the Facebook
This is extremely strange, and I'm hoping someone will have some insights to make
i'm extremely frustrated right now. I can't figure out why my container won't extend
I'm extremely confused by the proper behavior of UITableView cell rendering. Here's the situation:
So I'm creating my first chrome extension and was extremely confused for a while

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.