这可能是一个奇怪的问题,但我想知道你是否可以在c ++ 14中使用Java。 我并不真正关心GTK(我发现它令人困惑而且过于复杂)。 然而,Swing非常易于使用,您可以非常快速地完成工作项目。 所以我想知道你是否可以在c ++中使用Java Swing,所以我可以使用Swing作为前景,就像你看到的图形一样,并使用c ++作为背景,就像你看不到的东西,比如计算和对象和东西。 因此,如果我可以让c ++代码告诉Swing看起来像什么,或何时更新,那对我想到的项目非常有用。 提前感谢我收到的任何建议。
编辑:能够在Java中使用c ++ 14也是可以接受的。 此外,如果任何人都可以得到我的示例代码,这将是非常有帮助的。 谢谢!
This may be a bit of an odd question, but I would like to know if you can use Java inside c++14. I don't really care for GTK (I find it confusing and over complicated). Swing, however, is very easy to use, and you can get a working project very quickly. So I would like to know if you can use Java Swing inside c++, so I can use Swing as the foreground, as in what you see like graphics, and use c++ for the background, as in stuff you cant see, like calculations and objects and stuff. So if I can have c++ code tell Swing what to look like, or when to update, that would be very useful for the project I have in mind. Thanks in advance for any advice I may receive.
EDIT: Being able to use c++14 inside Java would be acceptable as well. Also, if anyone could get me example code also, this would be very helpful. Thanks!
最满意答案
您不应该从C ++运行Java,而是从Java运行C ++。 Oracle为您提供了一种使用JNI加载本机共享库的方法。
因此,您将使用Swing在Java中创建视图,然后通过调用在共享库中预编译和导出的C ++函数来更新视图。
也就是说,使用JNI非常棘手,C ++的速度提升可能不值得; 所以你应该考虑只使用Java(或者只使用C ++和库来创建你的GUI,比如Qt)
You shouldn't run Java from C++, but rather C++ from Java. Oracle gives you a way to load native shared libraries, using JNI.
So you would create your view in Java, using Swing, then you would update your view by calling C++ functions that were pre-compiled and exported in a shared library.
That said, using JNI is quite tricky and the speed improvements of C++ might not be worth it; so you should consider using only Java (or only C++ and a library to create your GUI, such as Qt)
更多推荐
发布评论