Enviado por CarlosF el día 3 de diciembre de 2005
El problema es q tengo q guardar en un archivo un Vector con objetos de esta clase:
public class Parche implements java.io.Serializable
{ double xs[],ys [],zs[];
double xpz[], ypz[];
int ixpz[], iypz[];
int pvx,pvy,pvz;
boolean unido;
double cenx,ceny,cenz, dist;
double size;
double atx=0,aty=0,atz=0;
java.awt.Graphics painter;
java.awt.Color lineColor;
java.awt.Color fillColor;
java.awt.Color backColor;
public Parche(java.awt.Graphics painter)
{ unido = false;
pvz=-100;
pvx = 0;
pvy = 0;
xs = new double [4];
ys = new double [4];
zs = new double [4];
xpz = new double [4];
ypz = new double [4];
ixpz = new int [4];
iypz = new int [4];
xs[0]=-50;
ys[0]=-50;
zs[0]=0;
xs[1]=50;
ys[1]=-50;
zs[1]=0;
xs[2]=50;
ys[2]=50;
zs[2]=0;
xs[3]=-50;
ys[3]=50;
zs[3]=0;
lineColor = new java.awt.Color(45,65,67);
fillColor = new java.awt.Color(45,65,67);
this.painter = painter;
this.painter.translate(385, 265);
proyeccion();
}
public Parche(java.awt.Graphics painter, int s)
{ unido = false;
pvz=-100;
pvx = 0;
pvy = 0;
xs = new double [4];
ys = new double [4];
zs = new double [4];
xpz = new double [4];
ypz = new double [4];
ixpz = new int [4];
iypz = new int [4];
xs[0]=-(s/2);
ys[0]=-(s/2);
zs[0]=0;
xs[1]=(s/2);
ys[1]=-(s/2);
zs[1]=0;
xs[2]=(s/2);
ys[2]=(s/2);
zs[2]=0;
xs[3]=-(s/2);
ys[3]=(s/2);
zs[3]=0;
lineColor = new java.awt.Color(45,65,67);
fillColor = new java.awt.Color(45,65,67);
this.painter = painter;
this.painter.translate(385, 265);
proyeccion();
}
public void setVisionPoint(int x, int y, int z)
{
pvx = x;
pvy = y;
pvz = z;
proyeccion();
}
public void setLineColor( java.awt.Color lineColor)
{
this.lineColor = lineColor;
}
public void setfillColor( java.awt.Color fillColor)
{
this.fillColor = fillColor;
}
public void size(float tam)
{
size = tam;
}
public void trasX(double tx)
{ if(!unido)
{
for (int i = 0 ; i <4;i++)
xs[i]+=tx;
}
proyeccion();
}
public void trasY(double ty)
{ if(!unido)
{
for (int i = 0 ; i <4;i++)
ys[i]+=ty;
}
proyeccion();
}
public void trasZ(double tz)
{ if(!unido)
{
for (int i = 0 ; i <4;i++)
zs[i]+=tz;
}
proyeccion();
}
public void escX(double sx)
{
if(!unido)
{
for (int i = 0 ; i <4;i++)
xs[i]*=sx;
}
proyeccion();
}
public void escY(double sy)
{ if(!unido)
{
for (int i = 0 ; i <4;i++)
ys[i]*=sy;
}
proyeccion();
}
public void escZ(double sz)
{ if(!unido)
{
for (int i = 0 ; i <4;i++)
zs[i]*=sz;
}
proyeccion();
}
public void rotX(double rx)
{ if(!unido)
{
for (int i = 0 ; i <4;i++)
{
ys[i]= (ys[i] * (java.lang.Math.cos(java.lang.Math.toRadians(rx)))) - ( zs[i] * (java.lang.Math.sin(java.lang.Math.toRadians(rx))));
zs[i]= (ys[i] * (java.lang.Math.sin(java.lang.Math.toRadians(rx)))) + ( zs[i] * (java.lang.Math.cos(java.lang.Math.toRadians(rx))));
}
}
proyeccion();
}
public void rotY(double ry)
{ if(!unido)
{
for (int i = 0 ; i <4;i++)
{
zs[i]= (zs[i] * (java.lang.Math.cos(java.lang.Math.toRadians(ry)))) - ( xs[i] * (java.lang.Math.sin(java.lang.Math.toRadians(ry))));
xs[i]= (zs[i] * (java.lang.Math.sin(java.lang.Math.toRadians(ry)))) + ( xs[i] * (java.lang.Math.cos(java.lang.Math.toRadians(ry))));
}
}
proyeccion();
}
public void rotZ(double rz)
{ if(!unido)
{
for (int i = 0 ; i <4;i++)
{
xs[i]= (xs[i] * (java.lang.Math.cos(java.lang.Math.toRadians(rz)))) - ( ys[i] * (java.lang.Math.sin(java.lang.Math.toRadians(rz))));
ys[i]= (xs[i] * (java.lang.Math.sin(java.lang.Math.toRadians(rz)))) + ( ys[i] * (java.lang.Math.cos(java.lang.Math.toRadians(rz))));
}
}
proyeccion();
}
public void proyeccion()
{ double zaux;
for (int c = 0; c < 4; c++)
{ //System.out.println("Punto de V "+pvx+","+pvy+","+pvz);
zaux = (pvz)/((pvz)-(zs[c]));
xpz[c]= pvx * (1 - zaux) + xs[c] * zaux;
ypz[c]= pvy * (1 - zaux) + ys[c] * zaux;
/*System.out.println("Punto "+c+"="+xs[c]+" ,"+ys[c]+" ,"+zs[c]);
System.out.println("Punto proyectado"+c+"="+xpz[c]+" ,"+ypz[c]);*/
}
}
public double maximoX()
{ double max=0;
for (int c = 0; c < 4; c++)
if(xs[c] > max)
max = xs[c];
return max;
}
public double minimoX()
{ double min=0;
for (int c = 0; c < 4; c++)
if(xs[c] < min)
min = xs[c];
return min;
}
public double maximoY()
{ double max=0;
for (int c = 0; c < 4; c++)
if(ys[c] > max)
max = ys[c];
return max;
}
public double minimoY()
{ double min=0;
for (int c = 0; c < 4; c++)
if(ys[c] < min)
min = ys[c];
return min;
}
public double maximoZ()
{ double max=0;
for (int c = 0; c < 4; c++)
if(zs[c] > max)
max = zs[c];
return max;
}
public double minimoZ()
{ double min=0;
for (int c = 0; c < 4; c++)
if(zs[c] < min)
min = zs[c];
return min;
}
public double distancia()
{
cenx = ( minimoX() + maximoX() ) / 2;
ceny = ( minimoY() + maximoY() ) / 2;
cenz = ( minimoZ() + maximoZ() ) / 2;
dist = Math.sqrt(Math.pow((cenx - pvx), 2) + Math.pow((ceny - pvy), 2) + Math.pow((cenz - pvz), 2));
System.out.println("Distancia "+dist);
return dist;
}
public void draw()
{ for (int i = 0; i < 4; i++)
{
ixpz[i]= (int) xpz[i];
iypz[i]= (int) ypz[i];
}
painter.setColor(fillColor);
painter.fillPolygon( ixpz, iypz, 4);
painter.setColor(lineColor);
painter.drawLine(ixpz[0],iypz[0],ixpz[1],iypz[1]);
painter.drawLine(ixpz[1],iypz[1],ixpz[2],iypz[2]);
painter.drawLine(ixpz[2],iypz[2],ixpz[3],iypz[3]);
painter.drawLine(ixpz[3],iypz[3],ixpz[0],iypz[0]);
/*for (int c = 0; c < 4; c++)
System.out.println("X:"+xpz[c]+" Y:"+ypz[0]);*/
}
}
y lo intento guardar asi:
public void saveFile(String path)
{ try
{
myOutFileStream = new java.io.FileOutputStream (path);
myOutZipStream = new java.util.zip.GZIPOutputStream(myOutFileStream);
myOutObjetStream = new java.io.ObjectOutputStream(myOutZipStream);
System.out.println("Beguin 1");
myOutObjetStream.writeObject(parches);
myOutObjetStream.flush();
System.out.println("Finish");
myOutObjetStream.close();
myOutFileStream.close();
System.out.println(path);
}
catch(Exception o)
{
System.out.println(o);
}
}
pero m sale esta excepcion:
java.io.NotSerializableException: sun.java2d.SunGraphics2D
no se por q...
si alguien m puede ayudar lo agradecere mucho....:P
Re: Problema Serializable
Enviado por yosbel el día 15 de marzo de 2008
tu problema se soluciona poniendo delante del painter transient para que cuando guardes tus datos lo pase por alto, queda de esta forma
transient java.awt.Graphics painter;