When applet is created, surface is also created. As I see in the code P2D/P3D/Java2D modes always somewhere call getScreenDevices
or getDefaultScreenDevice
functions. They throw HeadlessException
when called in headless mode. So in your case you should use virtual framebuffer.
The second option is to use Clojure2d
as an alternative. I created this library having exactly your problem in mind. Downside is Java2d mode only.