views:

153

answers:

1

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"

+2  A: 

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.

Adamski
Can you post the compile error in your original question along with the updated code? Also, I've edited my answer to highlight a second error.
Adamski
The compiler error message says "invalid method declaration; return type required"
Kevin Duke
The constructor spelling is incorrect: "DrawableExpolorer" and so the compiler thinks this is a method.
Adamski
Wow, can't believe I missed that one! Thanks!
Kevin Duke