My school projects are all done on the Linux Server, which is all done with command lines and no GUI. One of my java projects requires me to create a java GUI and to be able to build and run the project on the GL server.
I’m confused since the GL server is all command line, but my professor says that it can be done.
To connect to the school’s GL Server, I use Putty. I don’t know if it matters or not. And I’m using swing for Java GUI. I use ant to compile and run, and so will my professor when he grades it.
I built the program with success, but when I run it this comes up:
Buildfile: build.xml run: [java] Exception in thread "main" java.awt.HeadlessException: [java] No X11 DISPLAY variable was set, but this program performed an operation which requires it. [java] at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159) [java] at java.awt.Window.<init>(Window.java:406) [java] at java.awt.Frame.<init>(Frame.java:402) [java] at javax.swing.JFrame.<init>(JFrame.java:207) [java] at gui.PushCounter.main(PushCounter.java:18) [java] Java Result: 1 BUILD SUCCESSFUL Total time: 0 seconds
Is there a different class or method of creating a GUI in Java when you are working with command line? Is there another terminal I can log into other than Putty that would better suit using Java GUI? Is there some extra thing I have to add in my code or in the Linux Server?
Advertisement
Answer
Swing is probably a good choice for creating a GUI; I see no reason why you should change it.
I would suggest taking a look at X forwarding. With X forwarding, you SSH into the server as normal. The server runs all your code and handles the creation of your GUI. It then sends the window display information back to your machine.
I found a quick guide to configuring X forwarding in PuTTy. It should serve your needs well.
Caveats
For X forwarding to work, your SSH configuration must have it enabled. You can surely talk to your professor about this- it’s a simple change to the sshd config file. The speed of X forwarding shouldn’t be a concern if you and the server are both on campus, but note that this can be a drawback with other networking setups.