JavaFX移动外文翻译资料

 2022-05-05 09:05

JavaFX on Mobile

We all have heard many times the WORA slogan (“write once, run anywhere”), and while it is true that Java runs anywhere you have a JVM, thatrsquo;s not the case on modern mobile devices. While the latest trends confirm that smartphones are taking over computers, why canrsquo;t we target that huge market yet? Luckily, the open source project JavaFXPorts was born to allow all Java developers to deploy their projects on mobile (Android and iOS).

In this chapter, you learn about the JavaFXPorts project, and how this led to Gluon Mobile, a library created to enhance the mobile experience of the JavaFX desktop design.

As a full example, in this chapter, you will see how to create a simple JavaFX application with Gluon

Mobile: BasketStats. It is a simple app to track the annotation during a basketball game, and you will deploy it to Android and iOS.

Before getting into the example, letrsquo;s get started with JavaFXPorts and Gluon Mobile.

JavaFXPorts: The Port to Mobile

JavaFXPorts is the open source project that brings Java and JavaFX to mobile and embedded hardware. This includes iPhone, iPad, Android devices, and even the Raspberry Pi. The different projects that make possible this miracle can be found here: https://bitbucket.org/javafxports.

This adventure started at the end of 2013, when Johan Vos and his team started the work on porting JavaFX to Android, based on the OpenJFX project. In parallel, RoboVM started as a similar open source project to port Java to iOS. In February 2015, LodgOn and Trillian Mobile, the companies behind those projects, announced a joint effort to combine the best of both projects into a single plug-in, called jfxmobile-plugin. The one and only Gradle JavaFX plug-in for mobile was created and freely available through the JavaFXPorts repository.

A few weeks later, the Gluon company (see http://gluonhq.com) was created to gather all the efforts around the JavaFXPorts project and to deliver Gluon Mobile, a lightweight application framework and a set

of mobile controls to enhance the mobile experience.

JavaFXPorts Under the Hood

When we create and compile a Java application, the result is Java bytecode. To run it, you need the JRE,containing native libraries specific for each platform. Since there is no JRE for mobile devices, a different

approach is required.

On Android, the Googlersquo;s Android SDK contains tools for bundling applications, resources, and libraries into an Android package (APK). The jfxmobile plug-in will use these tools to create and install the Java mobile app, on top of the Androidrsquo;s Dalvik/Art VMs, relatively similar to the Java VM.

On iOS, the JRE needs to be packaged inside the app. The RoboVM ahead-of-time compiler is used to translate the Java code into native iOS code, linking the required runtime libraries with the application.

Both the Android runtime and the iOS AOT compiler currently use the Apache Harmony implementation of the Java class libraries, which is only a partial implementation of Java 7, and the project is officially abandoned. Adding to this, the RoboVM project has been stopped after Microsoft acquired

Xamarin, which acquired RoboVM in the first place.

At this moment, this means that JavaFXPorts supports most of the Java 7 SE APIs, and a few Java 8 APIs are supported as well (like lambda expressions, but not streams).

Because of these limitations, Gluon is working on GluonVM, a high-performance Java 8/9 VM that will leverage the OpenJDK class libraries and provide full Java 9 functionality on mobile devices. It is expected to be available at the time Java 9 is released.

Getting Started with JavaFXPorts

The documentation to get started creating Java mobile applications with JavaFXPorts can be found here:

http://docs.gluonhq.com/javafxports/.

The Gradle plug-in jfxmobile-plugin does almost all the required work. By including this plug-in in your regular JavaFX application, it will automatically create a number of tasks for you, and it will package

your application as a native iOS or a native Android package.

These are the prerequisites before starting a Java mobile project. On your machine:

Install the latest JDK 8 version for your development machine. Get it from here:http://www.oracle.com/technetwork/java/javase/downloads/index.html.

Install Gradle 2.2 or higher from https://gradle.org/install. It is required to build applications with the jfxmobile plug-in.

If you want to deploy on Android:

-Install the Android SDK from https://developer.android.com/studio/index.html.

You can download Android Studio, which bundles the SDK and the required Android tools, or you can just download and install the SDK tools at the end of the link.

– Run the Android SDK Manager (Android Studio -gt; Tools -gt; Android -gt; SDK

Manager or the command line lt;android sdkgt;/tools/android) and then install at least version 23.0.1 of Build-tools, the SDK Platform for APIs 21 up to 25, from Extras the Android Support Repository.

– Create a properties file in lt;Usersgt;/lt;Usergt;/.gradle/gradle.properties and add the ANDROID_HOME=lt;path.to.Android.sdkgt; property.

Before deploying to an Android device, you need to follow these steps on the device:

– Go to Settings -gt; About phone -gt; Build Number and tap seven times on it to

enable developer mode.

– Go to Settings -gt; Development Options -gt; USB Debugging and select enable.

– Go to Settings -gt; Security -gt; Unknown sources and enable installing apps from unknown sources.

If you want to deploy on iOS:

– You need a Mac with MacOS X 10.11.5 or higher

– You need Xcode 8.x or higher, available f

剩余内容已隐藏,支付完成后下载完整资料


JavaFX移动

我们都听说过很多次WORA口号(“编写一次,随处运行”),尽管Java在任何地方都有JVM,但在现代移动设备上却不是这样。虽然最新的趋势证实智能手机正在取代电脑,但我们为什么不能瞄准那个巨大的市场呢?幸运的是,开放源码项目JavaFXPorts诞生了,它允许所有Java开发人员在移动(Android和iOS)上部署他们的项目。

在本章中,您将了解JavaFXPorts项目,以及它如何导致了Gluon Mobile,这是一个用来增强JavaFX桌面设计的移动体验的库。

作为一个完整的示例,在本章中,您将看到如何使用Gluon创建一个简单的JavaFX应用程序。

移动:BasketStats。这是一个简单的应用程序,可以在篮球比赛中跟踪注释,然后将它部署到Android和iOS中。

在进入这个示例之前,让我们先从JavaFXPorts和Gluon Mobile开始。

JavaFXPorts:用于移动的端口

JavaFXPorts是将Java和JavaFX引入到移动和嵌入式硬件的开源项目。这包括iPhone、iPad、Android设备,甚至还有树莓派。使这个奇迹成为可能的不同项目可以在这里找到:https://bitbucket.org/javafxports。

这次冒险始于2013年年底,当时Johan Vos和他的团队基于OpenJFX项目开始了将JavaFX移植到Android上的工作。与此同时,RoboVM开始作为一个类似的开放源码项目,将Java移植到iOS中。在2015年2月,LodgOn和Trillian Mobile,这些项目背后的公司,宣布了一项联合努力,将两个项目的最佳组合合并到一个名为jfxmobile-plugin的插件中。通过JavaFXPorts存储库创建并免费提供了用于移动的唯一Gradle JavaFX插件。

几周后,Gluon公司(见http://gluonhq.com)被创建,以收集JavaFXPorts项目的所有努力,并交付Gluon Mobile,一个轻量级的应用程序框架和一个集合。

移动控制以增强移动体验。

JavaFXPorts引擎盖下面

当我们创建和编译Java应用程序时,结果是Java字节码。要运行它,您需要JRE,包含每个平台特定的本地库。因为移动设备没有JRE,这就不一样了。

方法是必需的。

在Android上,谷歌的Android SDK包含将应用程序、资源和库绑定到Android包(APK)的工具。jfxmobile插件将使用这些工具在Android的Dalvik/Art VMs之上创建和安装Java移动应用程序,与Java VM相对类似。

copy;卡尔Dea,Gerrit格,率先取得领先何塞Pereda,肖恩·菲利普斯和马克激烈质问者2017人

C。Dea等,以JavaFX 9为例,DOI 10.1007/978-1-4842-1961-4_13。

在iOS系统中,JRE需要被打包到应用程序中,而RoboVM ahead- time编译器被用来将Java代码转换为本地的iOS代码,并将所需的运行时库与应用程序连接起来。

目前,Android运行时和iOS AOT编译器都使用了Java类库的Apache Harmony实现,这只是Java 7的部分实现,项目正式被放弃。此外,在微软收购后,RoboVM项目已经停止。

Xamarin首先获得了RoboVM。

此时,这意味着JavaFXPorts支持大多数Java 7 SE api,也支持一些Java 8 api(比如lambda表达式,而不是流)。

由于这些限制,Gluon正在研究GluonVM,这是一个高性能的Java 8/9 VM,它将利用OpenJDK类库,并在移动设备上提供完整的Java 9功能。它预计在Java 9发布时可用。

开始使用JavaFXPorts

可以在这里找到使用JavaFXPorts创建Java移动应用程序的文档:

http://docs.gluonhq.com/javafxports/。

Gradle插件jfxmobile-plugin几乎完成了所有必需的工作。通过在常规JavaFX应用程序中包含这个插件,它将自动为您创建许多任务,并将打包。

您的应用程序作为本机iOS或原生Android包。

这些是启动Java移动项目之前的先决条件。在你的机器上:

-为您的开发机器安装最新的JDK 8版本。可以从这里下载:http://www.oracle.com/technetwork/java/javase/downloads/index.html。

-从https://gradle.org/install安装Gradle 2.2或更高版本。需要使用jfxmobile插件构建应用程序。

如果你想在Android上部署:

-从https://developer.android.com/studio/index.html安装Android SDK。

您可以下载Android Studio,它捆绑了SDK和所需的Android工具,或者您可以在链接的末尾下载并安装SDK工具。

-运行Android SDK管理器(Android Studio -gt;工具-gt; Android -gt; SDK)。

管理器或命令行/工具/android),然后安装至少版本23.0.1的构建工具,api 21的sdk平台,从额外的android支持存储库升级到25。

-在lt;用户gt;//.gradle/gradle中创建一个属性文件。属性并添加ANDROID_HOME=sdk gt;属性。

在部署到Android设备之前,您需要遵循以下步骤:

-到设置-gt;关于电话-gt;的建造数字,并点击七次。

使开发人员模式。

-进入设置-gt;开发选项-gt; USB调试和选择enable。

-到设置-gt;安全-gt;未知来源,并启用从未知来源安装应用程序。

如果你想在iOS上部署:

-你需要一个MacOS X 10.11.5或更高的Mac。

-你需要Xcode 8。x或更高,可从Mac应用商店购买。

在部署到iOS设备之前,需要从苹果开发人员门户获取配置文件。请参阅该链接,了解如何获得免费的部署到您自己的设备:http://docs.gluonhq.com/javafxports/#_ios_3。

你好Moblie World示例

有了所有的先决条件,让我们创建一个Hello Mobile World示例,您可以在桌面和移动平台上运行。

在您最喜欢的IDE上,您可以创建一个新的Gradle项目。给它一个名字(HelloMobile),一个位置,和一个主类,例如org.jfxbe.chap13 HelloMobile。

编辑的构建。gradle文件并添加清单13-1中的内容。它将应用jfxmobile插件。

到项目中。保存并重新加载项目以更新项目。第一次这样做时,插件将下载安装一些内部依赖项,因此可能需要一段时间。

注意,在撰写本文时,插件的版本是1.3.5。为了保持更新,请查看。

https://bitbucket.org/javafxports/javafxmobile-plugin。

现在,在主类中,扩展应用程序并创建一个包含一些内容的JavaFX场景,如清单13-2所示。

最后,您可以构建应用程序并在平台上运行它。要运行一个Gradle构建,只需键入Gradle,然后是所需的任务名称,例如Gradle build将构建这个项目。运行gradle运行在您的开发人员机器上运行它,gradle androidInstall将它部署到Android设备上,或者将launchIOSDevice部署到一个iOS设备上。图13-1显示了运行在Android上的应用程序的屏幕截图。

jfxmobile插件向您的Java应用程序添加了许多任务,这些任务允许您创建可以上载到苹果应用程序商店和Android Play商店的包。

jfxmobile插件下载并安装所需的JavaFX sdk:

- Android的dalvik SDK:插件目前依赖于org。javafxports:dalvik-sdk:8.60.9 org.javafxports:jfxdvk:8.60.9。

-Retrolambda插件:将代码转换为Java 6兼容的字节码,目前依赖于net.orfjack. retrolambda:retrolambda:2.5.1。

-iOS SDK:目前插件依赖于。

-org.javafxports:ios-sdk:8.60.9。

-MobiDevelop: RoboVM 1.8.0的分支,用于将代码编译到iOS兼容的字节码。目前取决于com.mobidevelop。robovm:robovm -区域:tar.gz:nocompiler:tripwire。

所提到的SDKs的源代码可以在这里找到:http://bitbucket.org/javafxports/ 8u-dev-rt。

在Android上,插件将执行一些命令,这些命令将导致在目录构建/javafxports/ Android中创建一个Android包(APK)。包将被部署并安装在设备中。清单13-3展示了Android中成功部署的输出,其中列出了所有涉及的任务。

在iOS中,情况在内部是不同的,但是Gradle命令是相似的。该插件将下载并安装RoboVM编译器,它将使用RoboVM编译器命令在构建/javafxports/ iOS中创建一个iOS应用程序。

最后,Gradle使用约定优于配置,而应用于插件的默认配置使构建成为可能。gradle文件非常简单。您可以在需要时修改此配置。请查看http://docs.gluonhq.com/javafxports/#anchor-3的文档,以获得关于Android和iOS的可修改属性的完整列表。

当你在你的移动设备上测试完这个应用程序后,你可以将它上传到苹果应用商店和安卓游戏商店。为此,插件已经包含了所需的任务。

在Android上,你需要提供有效的图标图像(在/src/ Android /res下)。

要在AndroidManifest文件中禁用调试选项:在应用程序标签下,添加android:debuggable='false'。最后你需要在app上签名,正如https://developer所解释的那样。android.com/studio/publish/app-signing.html。您可以将签名配置添加到您的构建中。gradle文件,如清单13-4所示。

如果一切都设置好了,运行gradle androidRelease来生成/构建/javafxports/ android的APK。要把它上传到商店,你必须注册谷歌游戏开发者(https://play.google)。并填写所需表格。

在iOS上,为应用提供图标,一旦你注册了苹果开发者计划,

您需要在应用程序上签名,以便生产,如清单13-5所示。运行gradle createIpa,并通过Xcode的开放开发者工具,在/build/javafxports/ios上提交应用程序。

应用程序加载器。通过在/src/ios/Default-Info.plist中添加适当的键到plist文件,来修复工具显示的初始需求。当这一切完成后,去iTunes Connect (https://itunesconnect.apple.com)准备发布的应用程序。与其他任何常规的iOS应用程序一样,通常需要几次迭代才能获得被批准提交的应用程序,直到你满足了审稿人的所有要求。

Gluon Mobile library的设计目的是帮助开发人员创建高性能、好看的、以及云连接的移动应用程序,从一个Java代码库到iOS和Android。它通过为现代材料设计用户界面提供api,访问移动设备特性,连接到web服务,并在许多设备上同步状态,从而提高了应用程序的上市时间。

Gluon Mobile是客户端库和开发工具:

-为客户端应用程序提供UI控件,使用Glisten,提供本机外观和感觉的UI组件,使用JavaFX控件和特定布局。

-处理与服务器端Gluon CloudLink的通信,使用Connect,一个允许与Gluon CloudLink本身和其他web服务通信的开放源码项目。在http://gluonhq.com/products/mobile/connect /中找到更多信息。

通过使用“魅力Down”(一个开放源码项目,提供文件系统、本地或推送通知、全球定位系统、传感器、摄像机等),可以在http://gluonhq找到更多的细节。com/products/mobile/charm-down/。

要开始使用Gluon Mobile,您可以从头创建一个Gradle项目,修改任何现有的示例(http://gluonhq.com/support/samples/),或者安装并使用您的IDE的Gluon插件。

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[463446],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。