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

  • Home
  • SEARCH
  • 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 7516195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:03:30+00:00 2026-05-30T01:03:30+00:00

This is quite difficult to phrase, but I need to be able to link

  • 0

This is quite difficult to phrase, but I need to be able to link a specific method to an object. More specifically, I’m making a graphics-oriented GUI, and I want to be able to assign an arbitrary method as the default “action” function for an element, such as a button.

That is, I created these interfaced “graphics” objects that basically have the ability to draw themselves. I would like them to handle their own actions, so I can, for example, do something like this:

GraphicObject b1 = new Button();
GraphicObject b2 = new Button();
b1.assignDefaultAction(---some method reference here--);
b2.assignDefaultAction(---a different method reference here--);

Then, if I do something like:

b1.action();
b2.action();

Each element will call its own referenced method independently. I believe this is possible to do in C++, but I haven’t seen it in Java. Is it even possible, or is there some kind of a workaround? The thing I’m trying to avoid is having to create specific abstraction for every single little thing I need to do, or litter my containing JPanel with a hundred specifications that just look messy.

Thank you for all your help.

  • 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-30T01:03:31+00:00Added an answer on May 30, 2026 at 1:03 am

    Buttons should use ActionListener implementations. Stick with Swing in that particular case.

    Your own classes can follow suit and start with a Command pattern interface:

    public interface Command {
        public void execute(Map<String, Object> parameters); 
    }
    

    Or maybe a better idea is to stick with the API that the JDK provides and try Callable.

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

Sidebar

Related Questions

Apologies for the vague title, but this is quite a difficult problem to explain
This is quite complicated but i would like to be able to refresh a
This is quite difficult to explain, but here goes. I have a Rails app
this will be quite difficult to explain. I hope I'm able to. I recently
I've been looking for the answer to this question but it seems quite difficult
I have this quite popular problem, but have failed to find a solution that
This is quite weird but my search function can search for any word except
This is quite a specific question, and I have had no luck on the
This is quite difficult to explain so I have attached an excel file here:
this is quite a difficult topic by all accounts. I am building a website

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.