Check what your environment variable DISPLAY's value is. Try running a simple X application from the command line. If it works, check DISPLAY's value for the right value.
You can experiment with different values of and environment variable on a per invocation basis by doing the following on the command line:
DISPLAY=:0.0 <your-java-executable-here>
How are you calling your program?