Hi. I'm making an interface and a class that correlates with the client code below. Everytime I try to compile the client code, I get the following errors:
Bird.java:15: = expected
private Color col;
^
Bird.java:16: = expected
private Point pos;
As well as a few others. For now, I'm concerned about this. I know that it has something to do with my interface obviously. However everytime I tweak with it and try to make it similar to the Hummingbird class, the compile error gets worse. Thank you for your time.
Client Code
import java.awt.*;
public class Aviary
{
public static final int SIZE = 20;
public static final int PIXELS = 10;
public static void main(String[] args)
{
DrawingPanel panel = new DrawingPanel(SIZE * PIXELS,
SIZE * PIXELS);
Graphics g = panel.getGraphics();
Bird[] birds =
{
new Hummingbird(2, 9), new Hummingbird(16, 11),
};
while (true)
{
g.setColor(Color.WHITE);
g.fillRect(0, 0, SIZE * PIXELS, SIZE * PIXELS);
for (Bird bird : birds)
{
bird.fly();
g.setColor(bird.getColor());
Point pos = bird.getPosition();
g.fillOval(pos.getX() * PIXELS,
pos.getY() * PIXELS,
PIXELS, PIXELS);
}
panel.sleep(500);
}
}
}
Interface
public interface Bird
{
public void fly();
private Color col;
private Point pos;
}
Hummingbird Class
import java.awt.*;
public class Hummingbird implements Bird
{
private Color col;
private Point pos;
public Hummingbird (int x, int y)
{
this.col = new Color(210, 10, 55);
this.pos = new Point(x, y);
}
public Color getColor()
{
return col;
}
public Point getPosition()
{
return pos;
}
public void fly()
{
pos = new Point((int)(Math.random()* 19),(int)(Math.random() * 19));
}
}