aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem in passing color as a parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in passing color as a parameter" Watch "Problem in passing color as a parameter" New topic
Author

Problem in passing color as a parameter

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
Hello everyone, below code is for bounce multiple balls, my code is working correctly, but when i m trying to add Color also as a parameter, it not changing the color of the balls, code is:

Point.java



Cfish.java



it's working fine but when i m adding color as a argument like this:

replace the point.java paint method:

replace the Cfish.java display method:


now it's not working..

how can i pass color as a parameter...??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

When you add a parameter to the paint method, you are no longer overriding it but overloading it instead. You need to keep a reference (instance field) to the color to use.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
can you please explain..?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

You know how to create an instance variable of type Color, don't you? Then you change display as you've tried before. paint keeps the same parameter list as originally though (only Graphics), and uses the instance variable in the calls to display.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
okay i got it, here is the code:



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
i want to know one more thing in this, how can i make this code into more object oriented form, is it possible?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem in passing color as a parameter