TowerDefense图像导入(eclipse,java)

TowerDefense图像导入(eclipse,java),java,eclipse,image,Java,Eclipse,Image,我一直在使用eclipse制作一个塔楼防御游戏,我无法打印出我的塔楼的图片。以下是主塔类的一些代码: public class MainTower { public String TextureFile = ""; public Image texture; //tower array that holds up to 150 towers public static final MainTower[] towerList = new MainTower

我一直在使用eclipse制作一个塔楼防御游戏,我无法打印出我的塔楼的图片。以下是主塔类的一些代码:

public class MainTower {    
    public String TextureFile = ""; 
    public Image texture;
    //tower array that holds up to 150 towers
    public static final MainTower[] towerList = new MainTower[150];          
    //Connecting the Lightning tower to the Main tower class    
    public static final MainTower towerOfLight = new LightningTower(0).getTextureFile("Lightning");

    public MainTower(int id)    {   
        if(towerList[id] != null){      
            System.out.println("[Tower Initialization] Two towers with the same id" + id);
        } else {            
            towerList[id] = this;       
            this.id = id;   
        }       
    }

    public MainTower getTextureFile(String str) {   
        this.TextureFile = str;         
        this.texture = new ImageIcon("/res/tower/" + this.TextureFile + "png").getImage();
        return null;
    } 
}
位置正确该图像是一个25x25 png图像,名为Lightning。下面是layout类中的一些代码:

for(int x = 0; x<15; x++) {
    for(int y = 0; y<2; y++) {
        if(MainTower.towerList[x *2 +y] != null)
            GUI.drawImage(MainTower.towerList[x * 2 + y].texture, (int) (12 + 12 + 250 + 40 + 12 +(x * towerWidth)), (12*50) + 20 + (y * (int)towerHeight), null);              
    GUI.drawRect((int) (12 + 12 + 250 + 40 + 12 +(x * towerWidth)), (int) ((12*50) + 20  + ((y * towerHeight))), (int)towerWidth,(int)towerHeight);         
        }     
   }
}

我看不懂那个密码。请正确格式化它。为什么getTextureFile是MainTower类型,为什么它返回null?我在没有太多java经验的情况下尽可能地重新格式化了您的代码。也许你还可以自己改进格式,让它更可读?你好,谢谢你,这是我第一次在这里发帖,所以我不知道怎么处理,我试着尽可能多地修改它。现在好多了。如果需要更多帮助,请阅读此有关格式设置的帮助页面:
//Creating a class for Lightning towers
public class LightningTower extends MainTower{

//Setting up Lightning tower id
    public LightningTower(int id){
        super(id);
    }
}