在非光栅图形配置中显示 JFrame

发布于 2024-10-31 03:22:23 字数 846 浏览 3 评论 0原文

您好,

我正在尝试在非屏幕设备中获取 JFrame 绘图。 JFrame 构造函数

 JFrame(GraphicsConfiguration) 

似乎允许这样做:

我的第一次尝试是创建自己的 GraphicsConfiguration,当调用 getType() 时,其 GraphicsDevice 报告 GraphicsDevice.TYPE_IMAGE_BUFFER 。

然而,JFrame.init 专门查找类型,如果类型不是 TYPE_RASTER_SCREEN,则抛出异常:

    if (graphicsConfig.getDevice().getType() !=
        GraphicsDevice.TYPE_RASTER_SCREEN) {
        throw new IllegalArgumentException("not a screen device");
    }

接下来,我尝试使返回的 GraphicsDevice 报告 GraphicsDevice.TYPE_RASTER_SCREEN。这使得 JFrame 能够正确初始化,但是当它显示它时,我得到了

Exception in thread "main" java.lang.ClassCastException: TestGraphicsConfiguration cannot be cast to sun.awt.X11GraphicsConfig

所以我已经用尽了关于如何绘制一个不显示在屏幕上但仍然完整的 JFrame 的想法布局合理且功能齐全。

我要掉进兔子洞了吗?或者这可以做到吗?

Greetings,

I'm trying to get a JFrame drawing in a non screen device. The JFrame constructor has a

 JFrame(GraphicsConfiguration) 

to seemingly allow this:

My First attempt was to create my own GraphicsConfiguration, who's GraphicsDevice reported GraphicsDevice.TYPE_IMAGE_BUFFER when getType() was called.

However JFrame.init specifically looks for the type and throws an exception if the type isn't TYPE_RASTER_SCREEN:

    if (graphicsConfig.getDevice().getType() !=
        GraphicsDevice.TYPE_RASTER_SCREEN) {
        throw new IllegalArgumentException("not a screen device");
    }

Next i tried to make the GraphicsDevice i returned report GraphicsDevice.TYPE_RASTER_SCREEN. This allowed the JFrame to be initialized correctly, but when it went to display it, I got

Exception in thread "main" java.lang.ClassCastException: TestGraphicsConfiguration cannot be cast to sun.awt.X11GraphicsConfig

So i've run out of ideas, on how to draw a JFrame that doesn't show up on the screen, but is never the less fully layed out and functional.

Am going down a rabbit hole here, or can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少跟Wǒ拽 2024-11-07 03:22:23

Java 顶级容器,例如 JFrame 需要访问 对等组件 主机平台本机,通常通过 JNI。或者,您可以使用 BufferedImagejava.awt.headless 模式,如 这里

附录:

我想知道“任何人”是否可以取代同伴的选择方式。

我不知道如何替换特定的对等组件,但可以调用特定于平台的本机组件; Java Native Access (JNA) 就是这样一种途径。作为一个极端的例子,这个 6502 JVM 在运行频率为 1 MHz 的 8 位处理器上以 128K 运行。演示(包括右下屏幕截图的)是使用 javac

A Java top-level container such as JFrame requires access to a peer component native to the host platform, typically via JNI. Alternatively, you may be able to use a BufferedImage or java.awt.headless mode, as discussed here.

Addendum:

I wonder if "any human" can replace how peers are selected.

I don't know how to replace a particular peer component, but it's possible to evoke platform-specific native components; Java Native Access (JNA) is one such avenue. As an extreme example, this 6502 JVM runs in 128K on an 8-bit processor running at 1 MHz. The demos, including source for the lower right screenshot, were compiled using javac.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文