Java Parent Class получает NULL на BufferedImageJAVA

Программисты JAVA общаются здесь
Anonymous
Java Parent Class получает NULL на BufferedImage

Сообщение Anonymous »

Я пытаюсь создать несколько дверей от родительских дверей и бабушек и бабушек. Каждая переменная имеет значение, которое я ожидаю, если он будет иметь, кроме BufferedImage. У него есть значение, которое я хочу, чтобы оно имело в Irondoor.
закрыто, замок и открытый, все это нулевые. Так что я понимаю, почему рисунка это null, но почему другие тоже?
Что я делаю не так с BufferedImage?public class Objects {

public boolean collision = true;
public int x, y, width, height;
public Rectangle solidArea;
public int tileSize, solidAreaX, solidAreaY, solidAreaWidth, solidAreaHeight;
protected ScreenPosition position;
protected BufferedImage drawThis;
public Keyboard keyboard;

public Objects() {
this.position = new ScreenPosition();
Screen screen = new Screen();
this.tileSize = 48;
this.width = tileSize;
this.height = tileSize;
this.solidAreaX = 0;
this.solidAreaY = 0;
this.solidAreaWidth = tileSize;
this.solidAreaHeight = tileSize;
this.solidArea = new Rectangle(solidAreaX, solidAreaY, solidAreaWidth, solidAreaHeight);
}
}

public class Door extends Objects {

public boolean locked = true, opened = false;
BufferedImage closed, padlocked, open;
Image image = new Image();

public Door () {
this.drawThis();
this.height = tileSize * 2;
}

private void drawThis() {
if(locked) {
opened = false;
super.drawThis = padlocked;
}
else if(opened) {
locked = false;
super.drawThis = open;
}
else {
super.drawThis = closed;
}
}
}

public class IronDoor extends Door {

public IronDoor(Keyboard keyboard, int x, int y, boolean locked) {
super.closed = image.getImage("/Objects/iron door closed.png");
super.padlocked = image.getImage("/Objects/iron door locked.png");
super.open = image.getImage("/Objects/iron door open.png");
super.keyboard = keyboard;
super.x = x;
super.y = y;
super.locked = locked;
}
}

//This is outside the classes:

ArrayList objects = new ArrayList();
objects.add(new IronDoor(keyboard, 180, 190, true));
objects.add(new IronDoor(keyboard, 300, 190, false));

//And this is where I make the image:
//I've been able to draw every other object I wanted with this class. But those objects weren't part of an inheritance.

public class Image {
public BufferedImage getImage(String path) {
BufferedImage image = null;
try {
image = ImageIO.read(getClass().getResourceAsStream(path));
}
catch (IOException e) {
e.printStackTrace();
}
return image;
}
}


Подробнее здесь: https://stackoverflow.com/questions/796 ... feredimage

Вернуться в «JAVA»