serialize rectangle2d.double

I wrote a mancala game that uses rectangle only to discover that it is not serializable. The quick and dirty solution to this was to use the early release of Java 6.0, as it makes rectangle serializable. This works for now, however, I realize it will only work when compiled on machines with 6.0. Is there another way to do this, such as making rectangle serializable; if so how might I approach that.

[408 byte] By [Dutena] at [2007-10-3 11:36:32]
# 1

Never mind, I figured it out. For those of you that may need to know in the future. This is what I did.

import java.awt.geom.*;

import java.io.*;

public class SerializableRectangle2D extends Rectangle2D.Double implements Serializable

{

public SerializableRectangle2D(double x, double y, double w, double h)

{

super(x, y , w, h);

}

public SerializableRectangle2D(Rectangle2D rect)

{

super(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());

}

private void writeObject(ObjectOutputStream stream) throws IOException

{

stream.writeDouble(x) ;

stream.writeDouble(y) ;

stream.writeDouble(width);

stream.writeDouble(height);

}

private void readObject(ObjectInputStream stream) throws IOException

{

x = stream.readDouble();

y = stream.readDouble();

width = stream.readDouble();

height = stream.readDouble();

}

}

Dutena at 2007-7-15 14:04:43 > top of Java-index,Security,Cryptography...