J
jprogrammer
I have a rendering class that extends AWT Panel for drawing purposes. I
made this class Serializable so that I can send it over the socket. The
problem I found out is that my implementation of writeObject () and
readObject() for my rendering frame is completely ignored!! Panel class's
default writeObject, readObject is invoked instead. I tested this using
println(). How do I fix this? Here's some code out of my class:
public class DrawFrame extends Panel implements Serializable,MouseListener,
MouseMotionListener{
public int side1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side3[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side4[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side5[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side6[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
//------------------
private void writeObject(ObjectOutputStream out)
{
try{
for(int i=0;i<9;i++)
{
out.writeInt(side1);
out.writeInt(side2);
out.writeInt(side3);
out.writeInt(side4);
out.writeInt(side5);
out.writeInt(side6);
}
}
catch(IOException e)
{
//System.out.println(e);
}
}
private void readObject(ObjectInputStream in)
{
try{
for(int i=0;i<9;i++)
{
side1=in.readInt();
side2=in.readInt();
side3=in.readInt();
side4=in.readInt();
side5=in.readInt();
side6=in.readInt();
}
}
//catch(ClassNotFoundException e){}
catch(IOException e){}
}
made this class Serializable so that I can send it over the socket. The
problem I found out is that my implementation of writeObject () and
readObject() for my rendering frame is completely ignored!! Panel class's
default writeObject, readObject is invoked instead. I tested this using
println(). How do I fix this? Here's some code out of my class:
public class DrawFrame extends Panel implements Serializable,MouseListener,
MouseMotionListener{
public int side1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side3[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side4[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side5[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
public int side6[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
//------------------
private void writeObject(ObjectOutputStream out)
{
try{
for(int i=0;i<9;i++)
{
out.writeInt(side1);
out.writeInt(side2);
out.writeInt(side3);
out.writeInt(side4);
out.writeInt(side5);
out.writeInt(side6);
}
}
catch(IOException e)
{
//System.out.println(e);
}
}
private void readObject(ObjectInputStream in)
{
try{
for(int i=0;i<9;i++)
{
side1=in.readInt();
side2=in.readInt();
side3=in.readInt();
side4=in.readInt();
side5=in.readInt();
side6=in.readInt();
}
}
//catch(ClassNotFoundException e){}
catch(IOException e){}
}