It isn't that difficult to load a font from resources the same way you are loading the images. I know this question was asked a year ago, but i hope to finally provide an answer.
Simply use the documentation here, which details how to load custom fonts into a GraphicsEnvironment
. It should look something like the following:
GraphicsEnvironment ge = null;
try{
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, game.getClass().getResourceAsStream("/fonts/fantasy.TTF")));
} catch(FontFormatException e){} catch (IOException e){}
Note: I use classInstance.getClass().getResourceAsStream(String fileDir)
to load the file from my resources directory in the Jar file.
After registering the font with the graphics environment, the font is available in calls to getAvailableFontFamilyNames()
and can be used in font constructors.
Hope this answers your question finally!