Without any further ado, let me first copy/paste the error I ran into today:
Exception in thread "main" java.lang.IllegalArgumentException: The font Arial is not available on your device.
at codedraw.TextFormat.setFontName(TextFormat.java:79)
at VierGewinnt.returnTheDefaultFont(VierGewinnt.java:734)
at VierGewinnt.enter_game_loop_for_the_GUI(VierGewinnt.java:860)
at VierGewinnt.run(VierGewinnt.java:979)
at VierGewinnt.<init>(VierGewinnt.java:174)
at VierGewinnt.main(VierGewinnt.java:987)
So, the font Arial is not on my linux system, or perhaps it can not be found.
If I omit specifying the Arial font, the very same program works fine. IF I specify
such a font that is not existing on my system, the program will instead terminate,
with the above error message.
(If you are curious, I ran into the above for the last assignment of EPROG1 where
we have to implement Vier Gewinnt.)
So it is not an issue for me; I can simply omit that line, or for EPROG1 presentation
I can put it back in - no problem. But I think this could also be improved a little.
For instance, one obvious solution would be to use the default fallback / generic
font. I assume CodeDraw already has a default font - after all if I do NOT specify
the Arial font, the same code base works fine. So one approach could be to
simply fall back towards that generic font. So the above would be displayed but
not terminate the program, instead, the fallback font is used. (One can reason
that it is my responsibility to handle such a use case via catch/throw, which I
can understand - but this would require adding a few more lines of code, so my
approach is to simply avoid Arial instead - less time investment.)
An alternative may be to add a way for users to specify a fallback font to use
in this event. That way the old behaviour is retained, but we could override
it via something like:
font.setDefaultFontName();
Or something like that. (Where font was: TextFormat font = new TextFormat(); )
There may be a few more ways to go about this, but I only wanted to a) report
this small issue, and b) give a very few suggestions how this could be improved.
If you also have time, perhaps https://github.com/Krassnig/CodeDraw/blob/master/INTRODUCTION.md
could mention a recommendation what to do when a font is not installed on a
given operating system. Although perhaps most folks use windows, no clue.
Anyway, that was it, thanks for polishing CodeDraw!