简体   繁体   English

如何在GL Linux服务器命令行中使用Java GUI?

[英]How using a Java GUI in a GL Linux Server command line?

My school projects are all done on the Linux Server, which is all done with command lines and no GUI. 我学校的项目都是在Linux Server上完成的,这全部是通过命令行完成的,没有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. 我的一个Java项目要求我创建一个Java GUI,并能够在GL服务器上构建和运行该项目。

I'm confused since the GL server is all command line, but my professor says that it can be done. 我很困惑,因为GL服务器都是命令行,但是我的教授说可以做到。

To connect to the school's GL Server, I use Putty. 要连接到学校的GL Server,我使用Putty。 I don't know if it matters or not. 不知道有没有关系 And I'm using swing for Java GUI. 而且我正在为Java GUI使用swing。 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? 使用命令行时,是否存在使用Java创建GUI的其他类或方法? Is there another terminal I can log into other than Putty that would better suit using Java GUI? 除了Putty之外,还有其他我可以登录的终端可以使用Java GUI进行登录吗? Is there some extra thing I have to add in my code or in the Linux Server? 我必须在代码或Linux Server中添加一些额外的东西吗?

Swing is probably a good choice for creating a GUI; 摆动可能是创建GUI的不错选择。 I see no reason why you should change it. 我认为您没有理由更改它。

I would suggest taking a look at X forwarding. 我建议看一下X转发。 With X forwarding, you SSH into the server as normal. 使用X转发,您可以像往常一样通过SSH进入服务器。 The server runs all your code and handles the creation of your GUI. 服务器运行所有代码并处理GUI的创建。 It then sends the window display information back to your machine. 然后它将窗口显示信息发送回您的计算机。

I found a quick guide to configuring X forwarding in PuTTy . 我找到了在PuTTy中配置X转发的快速指南 It should serve your needs well. 它应该很好地满足您的需求。

Caveats 注意事项

For X forwarding to work, your SSH configuration must have it enabled. 为了使X转发正常工作,您的SSH配置必须启用它。 You can surely talk to your professor about this- it's a simple change to the sshd config file. 您当然可以与您的教授讨论这-这是对sshd配置文件的简单更改。 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. 如果您和服务器都在园区中,则X转发的速度不应该成为问题,但是请注意,这对于其他网络设置可能是一个缺点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM