File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Action Performed on a set of Objects?

 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 356
Android Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic