This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

inherritence problem  RSS feed

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all

well , basicly what i'm trying to do is adding another small method to an excisting java class (ImageIcon)
any ideas if it's possible and in which direction should i go ?
thanks to all helpers!
 
Rancher
Posts: 1016
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you write that class?
 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i tried this :



but no go, i'm missing something
 
Ivan Jozsef Balazs
Rancher
Posts: 1016
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you actually want to achieve?
 
Author and ninkuma
Marshal
Posts: 66536
160
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could expand on what "no go" means?
 
twin yan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trying to get a method in there that will scale the photo to a certain height and width , the ImageIcon img1 is unneccesery just delete that

and i want that method to work on ImageIcons in my project
that's the goal
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

twin yan wrote:trying to get a method in there that will scale the photo to a certain height and width...
and i want that method to work on ImageIcons in my project ... that's the goal


OK, but I'm not quite sure how extending the class will help, unless you plan to make every Icon in your project "scaleable".

You've also written the method as if it was static. If you're writing it as an instance method for a 'ScalableIcon' class, then surely the method will act on the instance it's called on, so the signature should be:

public ImageIcon scale(int width, int height) {
   // code to scale 'this'
...


There's nothing basically wrong with what you've done, but to me it looks more like a static "utility" method; so if it was me, I'd probably put it in something like an 'ImageUtils' class.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!