如何制作 Java 跨平台 GUI 应用程序(Windows、Linux)?我应该使用哪些工具?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21194466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I make a Java cross-platform GUI application (Windows, Linux)? What tools should I use?
提问by MinimalTech
I'm new to Java GUI programming and I want to make a Java GUI application which can run both in Windows and Linux with the same code (the same executable/object file).
我是 Java GUI 编程的新手,我想制作一个 Java GUI 应用程序,它可以使用相同的代码(相同的可执行文件/目标文件)在 Windows 和 Linux 中运行。
Is that possible without any compatibility problems/errors/bugs?
这可能没有任何兼容性问题/错误/错误吗?
What else (like libraries, classes, packets) will I need to be able to design the GUI in Java?
我还需要什么(如库、类、数据包)才能用 Java 设计 GUI?
Should these libraries be present in every computer and every OS to be able for the application to run? Or the Java Virtual Machine (JVM) installed on a computer is enough?
这些库是否应该存在于每台计算机和每个操作系统中才能让应用程序运行?还是电脑上安装的Java虚拟机(JVM)就够了?
采纳答案by Jignesh Vasoya
Swing is the framework that can help you write GUI applications in Java. Have a look at the Swing tutorial from Oracle: http://docs.oracle.com/javase/tutorial/uiswing/
Swing 是可以帮助您用 Java 编写 GUI 应用程序的框架。看看 Oracle 的 Swing 教程:http: //docs.oracle.com/javase/tutorial/uiswing/
About platform compatibility: Most Linux distribution installs OpenJDK (open source alternative of Java) as default Java compiler. Mostly it works fine with the program written with Oracle JDK. But if you want to be sure, you can install Oracle JDK on Linux too.
关于平台兼容性:大多数 Linux 发行版都安装 OpenJDK(Java 的开源替代品)作为默认的 Java 编译器。大多数情况下,它适用于用 Oracle JDK 编写的程序。但是如果你想确定,你也可以在 Linux 上安装 Oracle JDK。
About development IDE: Eclipse and Netbeans are both available across multiple platforms including Windows and Linux.
关于开发 IDE:Eclipse 和 Netbeans 都可以跨多个平台使用,包括 Windows 和 Linux。
回答by user3208064
Swing will do this for you. It's not as pretty as native UI, but it works well and doesn't require any 3rd party libraries: http://docs.oracle.com/javase/tutorial/uiswing/
Swing 会为你做这件事。它不像原生 UI 那样漂亮,但它运行良好并且不需要任何 3rd 方库:http: //docs.oracle.com/javase/tutorial/uiswing/
回答by Typo
To run a java program you need the interpreter (Java Virtual Machine) installed on the computer, that is why it's portable to any OS as long a JVM is installed.
要运行 Java 程序,您需要在计算机上安装解释器(Java 虚拟机),这就是为什么只要安装了 JVM,它就可以移植到任何操作系统。
Eclipse is a good IDE.
Eclipse 是一个很好的 IDE。
The GUI is too extense, but mostly AWT and Swing packages.
GUI 过于广泛,但主要是 AWT 和 Swing 包。
回答by s3lph
- Before bothering about nice GUI's you should get yourselfs a deeper insight into Java.
- Java is always platform independent if you aren't using any special native libraries.
- I recommend coding the GUI yourself. I don't even know whether there are some GUI wizards. I recommend Eclipse, but that's purely opinion based...
- To get a cross-platform GUI which looks on every platform as a native program yould on the same, I'd recommend the Swing toolkit (
javax.swing.*
, already included into JRE/JDK)
- 在为漂亮的 GUI 烦恼之前,您应该对 Java 有更深入的了解。
- 如果您不使用任何特殊的本机库,Java 始终是独立于平台的。
- 我建议自己编写 GUI。我什至不知道是否有一些 GUI 向导。我推荐Eclipse,但这纯粹是基于意见......
- 要获得在每个平台上看起来都像本地程序一样的跨平台 GUI,我建议使用 Swing 工具包(
javax.swing.*
已包含在 JRE/JDK 中)
回答by Tejzeratul
You can use Eclipse IDE and for GUI you can go for either SWT or XWT
您可以使用 Eclipse IDE,对于 GUI,您可以选择 SWT 或 XWT