inheritance question

hey there :slight_smile:

here goes:
I use IndexColorModel to handle palettes at the moment, which is rather unflexible. So, I need a subclass of, or a wrapper for the IndexColorModel class. First choice is the subclass, of course :stuck_out_tongue:

The palettes are loaded from files, the method is done and works fine. But, how can this be implemented? The constructor call must be the first statement in the constructor, but how should it load the file then? (and using the arguments doesn’t seem very elegant to me, if it even works >_>)

don’t tell me this is not possible >_>

If you’re not going to make the subclass work like the superclass, don’t make it inherit it. Make a class that simply holds an IndexColorModel. Call your constructor which loads however you want, then make it initialize the IndexColorModel that it is holding.

it is supposed to work excactly like indexcolormodel, with the additional methods to load itself from a file.

well then I guess you wanna do what I suggested and call it a wrapper class :slight_smile:

public static IndexColorModel loadIndexColorModel(File file) {
  IndexColorModel result = null;
  try {
    // ...load the data from file...
    result = new IndexColorModel(bits, size, r, g, b);
  } catch (Exception e) {
    result = null;
  }
  return result;
}