Ok I realized I made I slight mistake in my post. By ".\NameOfJarFile.jar\" I actually meant that I put ".\\NameOfJarFile.jar\\". There are two things that I don't fully understand.
Firstly, Campbell mentioned I should put / instead of \ to maintain platform independence. But how could it maintain platform independence when I Windows the backslash \ is used :?: (I know Linux and MacOS use / but Windows is different, would a / still work in Windows?)
Secondly I have no idea what the method Icons.class.getResource(
String) does or where it comes from. Could you please briefly explain it to me or give me a link to it's API.
Regardless to that I still tried what Paul suggested and it worked fine when I ran it directly from the IDE. But after compressing the classes and image files into a JAR file the compiler gave me this error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at Cell.<init>(Cell.java:24)
at Board.<init>(Board.java:54)
at Application.<init>(Application.java:14)
at MainClass.main(MainClass.java:17)
Caused by: java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:138)
at Icons.clinit>(Icons.java:11)
... 4 more
I did recompile the classes and I checked that the PNG files are in the JAR file, so that's not the issue.