Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Extending the Color class  (Read 367 times)
0 Members and 1 Guest are viewing this topic.
Offline VaPS

Junior Member


Medals: 1



« Posted 2013-09-08 01:59:37 »

Hi, I'm trying to create additional methods for the class java.awt.Color:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public class Color extends java.awt.Color {

   private static final long serialVersionUID = 1L;

   public Color(float r, float g, float b) {
      super(r, g, b);
   }

   public static Color blend(Color c1, Color c2, float f) {
      return new Color(0F,0F,0F,0F);
   }

}


However, when the method blend is called Eclipse says "The method blend(Color, Color, float) is undefined for the type Color".
Do you have any suggestions what may be the problem?
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #1 - Posted 2013-09-08 02:08:25 »

Are you sure you imported YOUR Color class? Maybe giving it a different name would avoid confusion
Offline VaPS

Junior Member


Medals: 1



« Reply #2 - Posted 2013-09-08 02:10:28 »

Are you sure you imported YOUR Color class? Maybe giving it a different name would avoid confusion
All my classes are in the same package so yes. Regarding the name, I'm trying to extend the pre-defined class java.awt.Color, not create another. It would be neat not having to create a whole new class just for one method, that's why I'm trying to extend it.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 51
Projects: 11


Monkey for a head


« Reply #3 - Posted 2013-09-08 02:15:47 »

It depends on how you're calling it, but I suspect you're trying to override a static method, which won't work.

Don't bother with a custom subtype of Color - that's bad OOP. Instead just move your static blend() function into a utility class somewhere, then call it.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline VaPS

Junior Member


Medals: 1



« Reply #4 - Posted 2013-09-08 02:16:56 »

It depends on how you're calling it, but I suspect you're trying to override a static method, which won't work.

Don't bother with a custom subtype of Color - that's bad OOP. Instead just move your static blend() function into a utility class somewhere, then call it.
I guess I'll have to do it that annoying way.. Oh well, it's a fun learning experience nonetheless, thanks for the help!
Offline RobinB

JGO Knight


Medals: 37
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #5 - Posted 2013-09-08 21:05:08 »

You cant extend classes with adding functions.
When you do, a new class is created.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (23 views)
2014-04-15 18:08:23

BurntPizza (18 views)
2014-04-15 03:46:01

UprightPath (32 views)
2014-04-14 17:39:50

UprightPath (16 views)
2014-04-14 17:35:47

Porlus (32 views)
2014-04-14 15:48:38

tom_mai78101 (58 views)
2014-04-10 04:04:31

BurntPizza (116 views)
2014-04-08 23:06:04

tom_mai78101 (216 views)
2014-04-05 13:34:39

trollwarrior1 (183 views)
2014-04-04 12:06:45

CJLetsGame (190 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!