那要看自己的需要,对象序列化很容易的。比如你把圆,三角等都画到了panel上,那你就直接把panel序列化就可以了。

解决方案 »

  1.   

    http://java.sun.com/docs/books/tutorial/essential/io/providing.html
      

  2.   

    给你一个例子(已经调试过了,可以拿去体验一下):
    renxd 是一个保存我名字和年龄的类:
    package serize;public class renxd implements java.io.Serializable
    {
    String name;
    int age; public renxd()
    {
    name = "renxd";
    age = 23;
    }
    public String getName()
    {
    return name;
    }
    public int getAge()
    {
    return age;
    }
    }现在我将他序列化保存在一个文件中,然后再从这个文件中读出来:package serize;
    // Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
    // Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
    // Decompiler options: packimports(3) 
    // Source File Name:   test.javaimport java.io.*;
    import java.util.Date;public class test
    {
    renxd r;
    test()
    {
    //Date date = new Date();
    r = new renxd();
    String s = new String();
    int x = 0;
    try
    {
    FileOutputStream fileoutputstream = new FileOutputStream("dateFile.txt");
    ObjectOutputStream objectoutputstream = new ObjectOutputStream(fileoutputstream);
    objectoutputstream.writeObject(r);
    objectoutputstream.flush();
    }
    catch(Exception exception)
    {
    System.out.println("erro!!!");
    }
    try
    {
    FileInputStream fileinputstream = new FileInputStream("dateFile.txt");
    ObjectInputStream objectinputstream = new ObjectInputStream(fileinputstream);
    //Date date1 = (Date)objectinputstream.readObject();
    renxd z = (renxd)objectinputstream.readObject();
        //s = date1.toString();
    s = z.getName();
    x = z.getAge();
        objectinputstream.close();
    }
    catch(Exception exception1)
    {
        System.out.println("in error!!!");
    }
    int l = s.length();
    System.out.println(s+" "+l);
    System.out.println(x);
        }
        
        public static void main(String args[])
        {
            test t = new test();
        }
    }