62,614
社区成员
发帖
与我相关
我的任务
分享
public class Test
{
private int x;
private int y;
public Test(){}
public Test(int x, int y)
{
this.x = x;
this.y = y;
}
public Test(Test test)
{
this.x = test.getX();
this.y = test.getY();
}
public int getX()
{
return this.x;
}
public int getY()
{
return this.y;
}
}
//具有深复制的BufferImage
class UserBufferImage extends BufferedImage implements Cloneable
{
BufferedImage temp;
public UserBufferImage(int width, int height, int imageType)
{
super(width, height, imageType);
// TODO Auto-generated constructor stub
}
public void setImage(String a)
{
try
{
temp = ImageIO.read(new File("apple.jpg"));
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public BufferedImage getImage1()
{
return temp;
}
public Object clone() {
UserBufferImage o = null;
try {
o = (UserBufferImage) super.clone();
o.temp = myclone();
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return o;
}
//从temp复制一个新的BufferedImage对象
private BufferedImage myclone()
{
BufferedImage o=null;
o = new BufferedImage(temp.getWidth(null),temp.getHeight(null),BufferedImage.TYPE_INT_RGB);
Graphics g = o.getGraphics();
g.drawImage(temp,0,0,null);
g.dispose();
return o;
}
public static void getImage()
{
}
}
public Object clone() {
return super.clone();
}
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
class UserBufferImage extends BufferedImage implements Cloneable
{
BufferedImage temp;
public UserBufferImage(int width, int height, int imageType)
{
super(width, height, imageType);
// TODO Auto-generated constructor stub
}
public void setImage(String a)
{
try
{
temp = ImageIO.read(new File("apple.jpg"));
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public BufferedImage getImage1()
{
return temp;
}
public Object clone() {
UserBufferImage o = null;
try {
o = (UserBufferImage) super.clone();
o.temp = (BufferedImage) temp.clone();
} catch(CloneNotSupportedException e){
e.printStackTrace();
}
return o;
}
public static void getImage()
{
}
}
class temp
{
public static void main(String[] args)
{
UserBufferImage x = new UserBufferImage(20, 20, 3);
UserBufferImage y = (UserBufferImage) x.clone();
System.out.println(x.hashCode());
System.out.println(y.hashCode());
}
}