通过和接口实例化一个对象?

时间:2016-06-17 08:23:58

标签: java

我正在尝试执行一个切换案例,每次在找到数据库上的符号时实例化一个对象,但我无法实例化对象,因为它无法找到它。我在想是否必须通过界面或其他东西?

不要犹豫,问我任何问题!谢谢你们

“ViewPanel.java”

protected void paintComponent(final Graphics graphics) {

    for (x = 0; x < 21; x++) {
        for (y = 0; y < 14; y++) {
            char symbol = '-'; // {call Selectlvl1(x,y)}; ?

            switch (symbol) {
            case '+':
                VBone bone = new VBone(x, y);
                Arimages.add(bone.Image());
                break;
            case '-':
                Hbone bone = new HBone(x, y);
                Arimages.add(bone.Image());
                //
                break;
            case '#':
                Corners corner = new Corners(x, y);
                Arimages.add(corner.Image());
                //
                break;
            case 'x':
                Purse purse = new Purse(x, y);
                Arimages.add(purse.Image());
                //
                break;
            case 'o':
                CrystalBall crystal = new CrystalBall(x, y);
                Arimages.add(crystal.Image());
                //
                break;
            case '$':
                DoorC door = new DoorC(x, y);
                Arimages.add(door.Image());
                //
                break;
            case '@':
                DoorO door = new DoorO(x, y);
                Arimages.add(door.Image());
                //
                break;
            default:
                Black black = new Black();
                Arimages.add(black);
                break;
            }
        }
    }

    graphics.clearRect(0, 0, this.getWidth(), this.getHeight());
    for (Image img : Arimages) {

        graphics.drawImage(img, x * pixelNumbers, y * pixelNumbers, this);

        if (x == 21) {
            x = 0;
            y++;
        } else {
            x++;
        }
    }
}

例如“VBone.java”(所有对象类都相同):

public class VBone extends Background {
private int x;
private int y;

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

public int getX() {
    return x;
}

public void setX(int x) {
    this.x = x;
}

public int getY() {
    return y;
}

public void setY(int y) {
    this.y = y;
}

public void Image() throws IOException {
    BufferedImage vertical_bone = ImageIO.read(new File("src/main/resources/sprite/vertical_bone.png"));
}

}

层次结构(让我们说):

  

/view/ViewPanel.java

     

/model/elements/VBone.java

     

/contract/IModel.java /contract/IView.java

0 个答案:

没有答案