Question

I'm trying to make a maze game in Java.

The Explorer class represents the user, and the DrawableExplorer is the code that graphically represents the user. DrawableExplorer implements the Drawable interface which contains:

    import java.awt.Graphics;

    public abstract interface Drawable
    {
      public abstract void draw(Graphics paramGraphics);
    }

this compiles successfully however, I cannot figure out why my DrawableExplorer class isn't:

    import java.awt.*;
    public class DrawableExplorer extends Explorer implements Drawable

{

    public DrawableExpolorer(Square location, Maze maze, String name)
        {
            public void draw(Graphics g)
                {
                    Square location = location();
                    get.setColor(Color.BLUE);
                    g.fillOval(loc.x() + 10, loc.y() + 10, 30, 30);

                }
        }
}

It's asking for a return type but isn't my method void?

The compiler error message says "invalid method declaration; return type required"

Was it helpful?

Solution

You need to declare the class as:

public class DrawableExplorer extends Explorer implements Drawable

i.e. The extends clause has to come before the implements clause.

The other error is that you've declared your draw method within the body of the constructor for DrawableExplorer. Given that you've defined a constructor that takes three arguments you would typically want to process these within the constructor body (you currently ignore them); e.g. by assigning them to instance variables.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top