• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serializable and Shapes

 
Deirdre Hackett
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a interface called FCShape which I have said extends Serializable. I then have various classes that extend JComponent and implement FCShape. Instances of these classes are then stored in a vector.

The problem is that I would like to save this vector to a file using writeObject. This works for other objects but will not work for this vector.

Is this right? Is it something to do with the fact that the vector contains objects whos classes contain graphics objects? Is there a way around this?

Thanks in advance
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Deirdre Hackett:
I have a interface called FCShape which I have said extends Serializable. I then have various classes that extend JComponent and implement FCShape. Instances of these classes are then stored in a vector.

The problem is that I would like to save this vector to a file using writeObject. This works for other objects but will not work for this vector.

Is this right? Is it something to do with the fact that the vector contains objects whos classes contain graphics objects? Is there a way around this?


First, I would argue that your FCShape objects shouldn't contain
Graphics objects. The usual way to handle this would be for them
to have a painting method that accepts a Graphics object that they
keep in scope only for the duration of the call. Of course, I don't
know your actual requirements.

Second, there are ways around this. You can declare the Graphics
field to be v^Ho^Hl^Ha^Ht^Hi^Hl^He^H transient, for instance, or
you could have your FCShape object implement writeObject/readObject
methods, or have them implement the Externalizable interface.

The Swing forum probably isn't the best place to discuss this,
except for that bit about holding Graphics objects. Might I
recommend the I/O forum?

[edit: Oops, I got volatile and transient mixed up. Thanks, Mr. Ritchie.]
[ May 10, 2008: Message edited by: Brian Cole ]
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You sure you mean volatile, Brian? Maybe transient?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!