简体   繁体   English

如何以独立于平台的方式在 netbeans 中的 Java 框架内运行外部程序?

[英]How do I run an external program inside a Java frame in netbeans in a platform independent manner?

I am currently working on a research project for a University in which I am doing GUI interactions with my database and launching an external program based on the data.我目前正在为一所大学做一个研究项目,我正在与我的数据库进行 GUI 交互并基于数据启动一个外部程序。 I'm using runtime commands (once the OS is detected) to launch that external program with the selected data.我正在使用运行时命令(一旦检测到操作系统)使用所选数据启动该外部程序。

My question is how can I embed an external program's GUI inside a Java frame, if that is even remotely possible?我的问题是如何将外部程序的 GUI 嵌入到 Java 框架中,如果这甚至可以远程实现?

Given the clarifying comments on the question, the short answer is "no, you can't do that".鉴于对该问题的澄清评论,简短的回答是“不,你不能那样做”。

Java cannot display a native program's GUI within a JFrame, even if the target program was actually architected to allow it's GUI to be presented within another program's frame. Java 无法在 JFrame 中显示本机程序的 GUI,即使目标程序实际上被设计为允许其 GUI 在另一个程序的框架中呈现。

Are you using a console application?您正在使用控制台应用程序吗? You have to intercept its stdout to do it correctly.您必须拦截其标准输出才能正确执行。 So you can show the text that the 3rd party application is outputting in an UI control that you can put into JFrame.因此,您可以在 UI 控件中显示第 3 方应用程序正在输出的文本,您可以将其放入 JFrame 中。

It depends from the application you want to embed to the JFrame, but you can try to use jawt: https://docs.oracle.com/javase/9/docs/specs/AWT_Native_Interface.html It depends from the application you want to embed to the JFrame, but you can try to use jawt: https://docs.oracle.com/javase/9/docs/specs/AWT_Native_Interface.html

You will be able to get the native OS specific window handle and can draw on top of it, or can you use it as a container.您将能够获得特定于本机操作系统的 window 句柄并可以在其上绘制,或者您可以将其用作容器。 Note that only HW components are supported, so you will need to add Panel/Canvas to the JFrame and then use that for your native app.请注意,仅支持硬件组件,因此您需要将面板/画布添加到 JFrame,然后将其用于您的本机应用程序。

This is similar to this question: Native JNI/JAWT Swing application runs successfully on Java 6, but fails on Java 7 (64-bit Windows 7 OS) This is similar to this question: Native JNI/JAWT Swing application runs successfully on Java 6, but fails on Java 7 (64-bit Windows 7 OS)

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

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