Two Laptop Bag*
The moose likes Java in General and the fly likes Action Performed on a set of Objects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Action Performed on a set of Objects?" Watch "Action Performed on a set of Objects?" New topic
Author

Action Performed on a set of Objects?

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Okay so I was curious if there is a way to do an actionPerformed on multiple objects of the same type. For example I have a class called "Face" that has properties, but if I double click the object I want it to display all the properties of the Face(width, height, name, code, etc) in a dialog. This Face class is just properties, and it is called in my Draw class. Would I put this actionPerformed in my Face class itself(which seems like the most logical) and have each parameter change based on the Face I am currently clicking?

Thanks for any help,

~JO
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

the Face class does not seem like the right place for actionPerformed() to me.
if all the objects are of the same type actionPerformed() should work the same for all of them.

this is kind of different, but if you have several classes with the same method names but different implementations, you can use an interface so that actionPerformed() works the same for them all


SCJP
Visit my download page
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Randall Twede wrote:the Face class does not seem like the right place for actionPerformed() to me.
if all the objects are of the same type actionPerformed() should work the same for all of them.

this is kind of different, but if you have several classes with the same method names but different implementations, you can use an interface so that actionPerformed() works the same for them all


Well the thing is if I have multiple buttons I can set the actionPerformed of each of those buttons individually, but I want all of my Face objects to be able to run off of 1 actionPerformed method instead of making an actionPerformed for each since they all do the same. Sorry if I'm being confusing, and/or I'm confused....
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Jay Orsaw wrote:Well the thing is if I have multiple buttons I can set the actionPerformed of each of those buttons individually, but I want all of my Face objects to be able to run off of 1 actionPerformed method instead of making an actionPerformed for each since they all do the same. Sorry if I'm being confusing, and/or I'm confused....


So your Face class is going to have an actionPerformed method. And it's going to be an instance method, so when it's run you can use "this" if you need to know something about the particular Face object. That's perfectly normal object-oriented design; I think your only point of confusion is between the class and the objects of the class.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Paul Clapham wrote:
Jay Orsaw wrote:Well the thing is if I have multiple buttons I can set the actionPerformed of each of those buttons individually, but I want all of my Face objects to be able to run off of 1 actionPerformed method instead of making an actionPerformed for each since they all do the same. Sorry if I'm being confusing, and/or I'm confused....


So your Face class is going to have an actionPerformed method. And it's going to be an instance method, so when it's run you can use "this" if you need to know something about the particular Face object. That's perfectly normal object-oriented design; I think your only point of confusion is between the class and the objects of the class.


Okay so it was how I thought, thanks! When I do I'm creating a new Face Object right, or is my terminology wrong(Is there a site I can goto to learn the terminology better)? Also an Instance method is just any method like ? the same for right? A method that only has 1 "instance" per the amount of face classes I "instantiated?(correct term?)" Sorry for the confusion, thanks for the help again Paul!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Sure, here's a link to Oracle's tutorial about classes and objects: Lesson: Classes and Objects.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Action Performed on a set of Objects?
 
Similar Threads
Inner classes and Mediator Pattern
Doubt regarding EL
GUI errors
GUI classes, implementing ActionListener.
Serialization/Deserialization of an Array of Objects