gpt4 book ai didi

java - 在 Linux 终端中打开一个小程序

转载 作者:太空宇宙 更新时间:2023-11-04 12:32:49 25 4
gpt4 key购买 nike

我的要求是在 Linux 终端打开一个小程序。

我创建了一个 java 类和一个名为 A.java 和 A.html 的 html 文件,如下所示:

A.java:

public class A extends Applet
{
private int w, h;
public void init( )
{
System.out.println(" in init");
w = 45;
h = 50;
}

public void paint(Graphics g)
{
g.drawRect(w, h, 20, 80);
}
}

A.html:

     <html>
<p> This file launches the 'A' applet: A.class! </p>
<applet code="A.class" height=200 width=320>
</applet>
</html>

当我尝试执行它时,出现以下错误:

[root@VMS e42]# appletviewer A.java
[root@VMS e42]# appletviewer A.html
Exception in thread "main" java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
at java.awt.Window.<init>(Window.java:536)
at java.awt.Frame.<init>(Frame.java:420)
at java.awt.Frame.<init>(Frame.java:385)
at sun.applet.AppletViewer.<init>(AppletViewer.java:159)
at sun.applet.StdAppletViewerFactory.createAppletViewer (AppletViewer.java:98)
at sun.applet.AppletViewer.parse(AppletViewer.java:1158)
at sun.applet.AppletViewer.parse(AppletViewer.java:1092)
at sun.applet.Main.run(Main.java:156)
at sun.applet.Main.main(Main.java:98)

我需要改变什么?

最佳答案

错误消息不言自明:您需要提供一个 X11 服务器(并设置您的 DISPLAY 环境变量以指向它)。小程序是 AWT 类,需要图形显示;你不能在普通终端上运行。

顺便说一句,以 root 身份运行是个坏主意;以 root 身份运行 X11 应用程序是一个更糟糕的主意。

关于java - 在 Linux 终端中打开一个小程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42807486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com