Die Java -Elternklasse empfängt Null auf BufferedImageJava

Java-Forum
Anonymous
 Die Java -Elternklasse empfängt Null auf BufferedImage

Post by Anonymous »

Ich versuche, mehrere Türen aus den Objekten der Elterntür und Großeltern zu erstellen. Jede Variable hat den Wert, von dem ich erwarte, dass er außer den gepuffertenImage -Seite hat. Es hat den Wert, den ich möchte, dass es in Irondoor hat. Also verstehe ich, warum Drawthis null ist, aber warum auch die anderen auch?
Was mache ich mit Bufferedimage falsch?

Code: Select all

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;
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post