ImageIcon and Model-View-Controller

ImageIcon and Model-View-Controller

Post by baker » Sat, 22 Jan 2005 19:17:36


Hi there,

I am struggling with implementing a Model-View-Controller application
with a Swing View. The specific problem I am having is that I don't
want to include any Swing classes in the Model (they belong in the
View, right?) but I want my users to have a picture associated with
them. I would naturally have getter/setter and member variable of type
ImageIcon to hold this picture. But then I have Swing classes in my
Model. Then if I want to write a web-based Model I have these
extraneous ImageIcons that are not much use to me.
Can you see a better way?

Thanks,

Tom
 
 
 

ImageIcon and Model-View-Controller

Post by Matt Humph » Sat, 22 Jan 2005 22:42:38


Let the model have the raw bytes of the image (.gif, .jpg, .png) and make UI
convert these to ImageIcon or Image or whatever for display. A nice
advantage is that your model will still be web compatible. If you're using
a DB you can put the bytes into a BLOB or stick them in a file. byte [] is
reasonably easy to work with.

Cheers,
Matt Humphrey XXXX@XXXXX.COM http://www.yqcomputer.com/