这是我的课程,一切都完成了:
import java.awt.Color;
import java.awt.Graphics;
//This class will not compile until all
//abstract Locatable methods have been implemented
public class Block implements Locatable
{
//instance variables
private int xPos;
private int yPos;
private int width;
private int height;
private Color color;
//constructors
public Block () {}
public Block(int x,int y,int w,int h)
{
xPos = x;
yPos = y;
width = w;
height = h;
}
public Block(int x,int y,int w,int h, Color c)
{
xPos = x;
yPos = y;
width = w;
height = h;
color = c;
}
//set methods
public void setBlock(int x, int y, int w, int h)
{
xPos = x;
yPos = y;
width = w;
height = h;
}
public void setBlock(int x, int y, int w, int h, Color c)
{
xPos = x;
yPos = y;
width = w;
height = h;
color = c;
}
public void draw(Graphics window)
{
window.setColor(color);
window.fillRect(getX(), getY(), getWidth(), getHeight());
}
//get methods
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
//toString
public String toString()
{
String complete = getX() + " " + getY() + " " + getWidth() + " " + getHeight() + " java.awt.Color[r=" + color.getRed() + ", g=" + color.getGreen() + ", b=" + color.getBlue() + "]";
return complete;
}
}
这是我必须实现的接口类:
public interface Locatable
{
public void setPos( int x, int y);
public void setX( int x );
public void setY( int y );
public int getX();
public int getY();
}
我还没有关于接口/实现的正式指导,因此,我不确定需要做什么才能让第一堂课正常运行