Y-Animation

Unkownsyntax

Bekanntes Mitglied
Java:
public interface Animation {

    void animate(int frame);

}
Java:
public abstract class Figure implements Animation{

    private int x;
    private int y;

    public Figure(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return this.x;
    }

    public int getY() {
        return this.y;
    }

    abstract void draw(int xOrigin, int yOrigin);
    
    Animation createXAnimation(){
        return new Animation(){

          public void animate(int frame){
          Figure.this.x =+ frame;

          }
        };
    }

}


Hier nun mein problem:

The interface Animationis provided to you,it contains the method void animate(int frame)and is called from the Controller at each frame. Create a method Animation createXAnimation() in the class Figure. Use an anonymous inner class for implementing the Animation interface. The animation should increase the x- coordinate of the figure at every frame. Additionally, create a method Animation createYAnimation(). For implementing this method, you should create a named static inner class called YAnimation. Add one additional create???Animation(???) method and implement another simple animation (be creative). In a comment, explain the advantages and disadvantages of using an anonymous inner class compared to a named inner class.

Mit der x- Koordinate hab ich es hinbekommen aber mit der inneren anonymen klasse weiß ich nicht wie ich das machen soll genau. Hat da wer eine idee?
 
> aber mit der inneren anonymen klasse weiß ich nicht wie ich das machen soll genau.

die Annimation mit x ist doch genau eine inneren anonymen klasse

die Syntax für eine benannte innere Klasse sollte dir eigentlich bekannt sein wenn du eine Aufgabe dazu hast,
in Kurzform:
class X extends ... {
}
innerhalb der äußeren Klasse schreiben, mit oder ohne static-Schlüsselwort, was gewisse Auswirkungen hat

aber am besten alles nachlesen, die google-Schlüsselwörter dürften klar sein, führt etwa zu
Java innere Klasse und statische verschachtelte Klasse

Insel-Buch ist gewiss auch hilfreich
Galileo Computing :: Java ist auch eine Insel (8. Auflage) – 9.2 Geschachtelte (innere) Klassen, Schnittstellen, Aufzählungen
 
ok danke mal für das aber ich habe das problem dass die klasse static sein soll. Ich habe nicht wirklich eine idee wie ich dass programmieren kann mit non static hab ich es schon geschafft. Ist ja eig. gleich wie bei anonym

Java:
    Animation createYAnimation() {

        return new YAnimation();
    }

     class YAnimation implements Animation {

        YAnimation() {
            super();
        }

        public void animate(int frame) {
            Figure.this.y=+frame;
        }
    }
 
bei einer static-Klasse musst du wohl das Figure-Objekt als Parameter im Konstruktor übergeben
 

Zurück
Oben