0

Simpleを使用して、XMLファイルをこのクラスに読み込もうとしています。クラスに正しく注釈を付けたかどうかは本当にわかりません。

この部分が必要かどうかわかりません:

public Frame()
{
    super();
}

public Frame(int num, int x, int y, int width, int height,int offsetx,int offsety, int duration )
{
    this.Num = num;
    this.X = x;
    this.Y = y;
    this.Width = width;
    this.Height = height;
    this.OffsetX = offsetx;
    this.OffsetY = offsety;
    this.Duration = duration;]

super()は何をしますか?ゲッター/セッターは必要ですか?ゲッターまたはセッターを追加したものですか?彼らは自動的に自分自身を呼びますか、それとも何ですか?

フルクラスは次のとおりです。

public class SpriteAnimationManag 
{
// Animation frame class



@Element(name = "Frame")
public class Frame
{

    @Element(name = "Num")
    public int Num;


    @Element(name = "X")
    public int X;

            @Element(name = "Y")
    public int Y;


    @Element(name = "Width")
    public int Width;


    @Element(name = "Height")
    public int Height;


    @Element(name = "OffSetX")
    public int OffsetX;


    @Element(name = "OffSetY")
    public int OffsetY;


    @Element(name = "Duration")
    public float Duration;

    public Frame()
    {
        super();
    }

    public Frame(int num, int x, int y, int width, int height,int offsetx,int offsety, int duration )
    {
        this.Num = num;
        this.X = x;
        this.Y = y;
        this.Width = width;
        this.Height = height;
        this.OffsetX = offsetx;
        this.OffsetY = offsety;
        this.Duration = duration;
    }



}

// Animaiton class to hold the name and frames
public class Animation 
{

    @Element(name = "Name")
    public String Name;


    @Element(name = "FrameRate")
    public int FrameRate;//may need elementarray or list???

    @Element(name = "Loop")
    public boolean Loop;

    @Element(name = "Pingpong")
    public boolean Pingpong;


    @ElementArray(name = "Frames") 
    public Frame[] Frames;

public Animation()
{
    super();
}

public Animation(String name, int framerate, boolean loop, boolean pingpong, Frame[] frames)
{
this.Name = name;
this.FrameRate = framerate;
this.Loop = loop;
this.Pingpong = pingpong;
this.Frames = frames;
}


}

// The Sprite Texture stores the Sprite Sheet path.fr
public class SpriteTexture 
{
    // The Sprite Sheet texture file path

    @Element(name = "path")
    public String Path;

    public SpriteTexture()
    {
        super();
    }

    public SpriteTexture(String path)
    {
        this.Path = path;
    }

}

// Aniamtion Set contains the Sprite Texture and Animaitons.

@Root(name = "Animations")
public static class XNAAnimationSet
{
    // The sprite texture object

    @Element(name = "Texture")
    public SpriteTexture SpriteTexture;

    // The animation array in the Animation Set
        @ElementArray(name = "Animation")
    public Animation[] Animations;

    public XNAAnimationSet()
    {
        super();
    }

    public XNAAnimationSet(SpriteTexture spritetexture, Animation[] animations)
    {
        this.SpriteTexture = spritetexture;
        this.Animations = animations;
    }
}

// Sprite Animation Manager class
public final static class SpriteAnimationManager 
{
    private static final String XNAAnimationSet = null;//was static private static
    public static int AnimationCount;

    // Read the Sprite Sheet Description information from the description xml file
    public static XNAAnimationSet Read(String filename) throws Exception
    {

         XNAAnimationSet animationSet = new XNAAnimationSet();


             Serializer serializer = new Persister();

             try {
                animationSet = serializer.read(XNAAnimationSet.class, filename );

            } 
             catch (Exception e)
             {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        // Count the animations to Animation Count
        AnimationCount = animationSet.Animations.length;

        return animationSet;
    }
  }
}

クラスをファイルに書き込もうとして、何が読み取られているかを確認しようとしています。ファイルは作成されましたが、空です。

私がこれに正しく注釈を付けたかどうか誰かに教えてもらえますか?私は何が間違っているのですか?

4

1 に答える 1

1

私は最後の日にjaxbを使用してxmlを解析していました。あなたのやり方とどれほど似ているかはわかりませんが、必要なもののいくつかについて言及していません:

まず、クラスに引数なしのコンストラクターが必要だと思います。これは、あなたにとっては-

public Frame(){};

ゲッターが必要だと思います。そこにあるのはゲッター/セッターではなく、変数を宣言するだけです。これは本当に基本的なJavaのものなので、続行する前に読む価値があるかもしれません。ゲッターを適切に定義したら@XMLElement、変数宣言子の上ではなく、それぞれの上に注釈を配置します。ゲッターは次のようになります。

@XMLElement    
public string getName(){ return this.Name};

また、一度に 1 つのクラスを解析することをお勧めします。ここには複数の内部クラスがあり、解析しようとすると乱雑になると思います。@RootElementクラス名宣言子の上にある必要があると思います。したがって、xml はどのタイプのあなたの作成に反対します。

とにかく、頭のてっぺんからいくつかのことがありますが、頑張ってください!

于 2012-11-17T14:03:12.010 に答える