Class independent way to get the ClassLoader

This is a trivial change, but can we change the way to get the ClassLoader before getting the resource for the TextureManager? When going through the FlagRush tutorials, and moving from one lesson to the next, I keep forgetting to change the class name accordingly. For example, in Lesson 1, the code is:

<code>

TextureManager.loadTexture(Lesson1.class.getClassLoader().getResource("jmetest/data/images/Monkey.jpg")

</code>

I propose the code be changed to:

<code>

TextureManager.loadTexture(Thread.currentThread().getContextClassLoader().getResource("jmetest/data/images/Monkey.jpg")

</code>

In this case, we don't have to keep changing the name of the class from Lesson1 to Lesson2, and so on.



Roslan


i wouldn't do that but if you want to do it we should propably use:


getClass().getClassLoader().getResource(..);



also: the code tags use these brackets: []

Thanks. That's a shorter way to do it. :slight_smile:


Another thing. getClass() won't work in static methods like main(). So, we have to use Lesson1.class or the Thread option.



Regards

roslamir said:

Another thing. getClass() won't work in static methods like main(). So, we have to use Lesson1.class or the Thread option.


Right you are. Now i know why all the test cases use Lesson1.class.... because many things happen in the main() of the test cases.  :)

All in all I think its best to leave it as it is and in our own classes we can do it as we please  :wink: