移动设备上的JavaFX外文翻译资料

 2022-05-02 10: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.

copy; Carl Dea, Gerrit Grunwald, Joseacute; Pereda, Sean Phillips and Mark Heckler 2017

431

C. Dea et al., JavaFX 9 by Example, DOI 10.1007/978-1-4842-1961-4_13

Chapter 13 ■ JavaFX on Mobile

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.

■■Note Until GluonVM is released and given the mentioned limitations, to run JavaFX on Mobile we canrsquo;t use Java 9 nor the modular system. That is why the examples in this chapter use the existing implementation (Java 7 and some features of Java 8).

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 Pla

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


外文翻译

移动设备上的JavaFX:

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

在本章中,您将了解JavaFXPorts项目,以及它是如何导致Gluon Mobile的,Gluon Mobile是为增强JavaFX桌面设计的移动体验而创建的。

作为一个完整的示例,在本章中,您将看到如何使用Gluon Mobile : BasketStats创建一个简单的JavaFX应用程序。这是一个在篮球比赛中跟踪注释的简单应用程序,您将把它部署到Android和iOS。

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

JavaFXPorts :移动设备的端口:

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

这一冒险始于2013年底,当时Johan Vos和他的团队开始基于OpenJFX项目将JavaFX移植到Android。与此同时,RoboVM开始时是一个类似的开源项目,将Java端口连接到iOS。2015年2月,这些项目背后的公司lochon和Trillian Mobile宣布了一项计划,将这两个项目中最好的项目合并为一个插件,称为jfxmobile - plugin。创建了唯一一个Gradle JavaFX移动插件,并通过JavaFXPorts存储库免费提供。几周后,Gluon公司成立,旨在收集JavaFXPorts项目的所有工作,并提供Gluon Mobile,一个轻量级应用程序框架和一组移动控制,以增强移动体验。

JavaFXPorts在保护下运动:

当我们创建和编译Java应用程序时,结果就是Java字节码。要运行它,您需要JRE,其中包含每个平台特定的本机库。由于移动设备没有JRE,因此需要一种不同的方法。

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

在iOS上,JRE需要打包在应用程序中。RoboVM提前编译器用于将Java代码转换为本机iOS代码,从而将所需的运行时库与应用程序链接起来。

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

此时,这意味着JavaFXPorts支持大多数Java 7se应用编程接口,也支持少数Java 8应用编程接口(如lambda表达式,但不支持流)。

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

■注意,在GluonVM发布并给出上述限制之前,要在Mobile上运行JavaFX,我们不能使用Java 9或模块化系统。这就是本章中的示例使用现有实现( Java 7和Java 8的一些功能)的原因。

开始使用JavaFXPorts

开始使用JavaFXPorts创建Java移动应用程序的文档可以在这里找到Gradle插件jfxmobile插件几乎完成了所有必需的工作。通过将此插件包含在常规JavaFX应用程序中,它将自动为您创建许多任务,并将您的应用程序打包为本机iOS或本机Android包。这些是启动Java移动项目之前的先决条件。在您的机器上:

––为您的开发计算机安装最新的JDK 8版本。从这里获取

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

如果要在Android上部署:

––从https : / / developer . Android . com / Studio / index . html安装Android SDK。您可以下载Android Studio,它将SDK与所需的Android工具捆绑在一起,也可以在链接末尾下载并安装SDK工具。

––运行Android SDK管理器( Android Studio - - amp;gt;工具- - amp;gt; Android - - amp;gt; SDK管理器或命令行amp;lt; Android SDK amp;gt; / Tools / Android ),然后从Android支持存储库中额外安装至少23 . 0 . 1版的构建工具(适用于api21的SDK平台,最多25个)。

––在amp;lt; Users amp;gt; / amp;lt; User amp;gt; / )中创建属性文件。并添加ANDROID _ HOME = amp;lt;路径到. ANDROID . SDK amp;gt;属性。

在部署到Android设备之前,您需要在设备上执行以下步骤:

––转到“设置”- amp;gt;“关于电话”- amp;gt;“生成编号”,然后轻按七次以启用开发人员模式。

––转到“设置”- amp;gt;“开发选项”- amp;gt;“USB调试”,然后选择“启用”。

––转到“设置”- amp;gt;“安全性”- amp;gt;“未知源”,并启用从未知源安装应用程序。

如果要在iOS上部署,请执行以下操作:

––您需要配备MacOS X 10 . 11 . 5或更高版本的Mac

––您需要Xcode 8.x或更高版本,可从Mac应用商店购买

在部署到iOS设备之前,您需要从Apple开发人员门户获取资源调配配置文件。请参阅此链接,了解如何获得一个免费的设备以部署到您自己的设备上: http : / / docs . gluonhq . com / javafxports / # _ IOs _ 3。

你好,移动世界示例

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

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

Listing 13-1.ensp; The build.gradle File

buildscript { repositories {

jcenter()

}

dependencies {

classpath #39;org.javafxports:jfxmobile-plugin:1.3.5#39;

}

}

apply plugin: #39;org.javafxports.jfxmobile#39;

repositories { jcenter()

}

mainClassName = #39;org.jfxbe.chap13.HelloMobile#39;

jfxmobile { android {

}

ios {

forceLinkClasses = [ #39;org.jfxbe.chap13.**.*#39; ]

}

}

433

第13章■移动上的JavaFX

请注意,编写本文时插件的版本是1 . 3 . 5。要保持更新,请查看。

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

Listing 13-2.ensp; Hello Mobile Main Class

package org.jfxbe.chap13;

import javafx.application.Application; import javafx.geometry.Rectangle2D; import javafx.scene.Scene;

import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.stage.Screen;

import javafx.stage.Stage;

public class HelloMobile extends Application {

@Override

public void start(Stage primaryStage) throws Exception { Rectangle2D bounds = Screen.getPrimary().getVisualBounds(); final Button button = new Button('Hello Mobile World!'); button.setStyle('-fx-font-size: 20pt;');

button.setOnAction(e -gt; button.setRotate(button.getRotate() - 30));

final StackPane stackPane = new StackPane(button);

Scene scene = new Scene(stackPane, bounds.getWidth(), bounds.getHeight()); primaryStage.setScene(scene);

primaryStage.show();

}

public static void main(String[] args) { launch(args);

}

}

最后,您可以构建应用程序并在您的平台上运行它。要运行渐变生成,只需键入渐变,然后键入所需的任务名称,例如渐变生成将生成项目。运行gradle run可在开发人员计算机上运行,运行gradle androidintstall可在Android设备上部署,或运行gradle启动设备到iOS设备。图13 - 1显示了在Android上运行的应用程序的屏幕截图。

它是怎么工作的?

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

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

––Android的Dalvik SDK :插件当前依赖于组织。该组织的成员包括:达尔维克- SDK : 8 . 60 . 9和jfafxports : jfxdvk : 8 . 60 . 9。

––Retrolambda插件:将代码转换为Java 6兼容的字节码,目前依赖于。

––IOs - SDK :插件当前依赖于组织。

––mobidedevelop : RoboVM 1 . 8 . 0的分支,用于将代码编译为与iOS兼容的字节码。目前依赖于移动开发。

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

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

第13章■移动上的JavaFX

■请注意,在运行分级任务时,使用- info、- debug或- stracktrace可获得更详细的输出,这可能有助于您ping指示错误和问题,例如分级信息androidInstall。

将应用程序提交到商店

完成移动设备上的应用程序测试后,您可以继续将其上载到Apple应用程序商店和Android Play商店。为此,插件已经包括所需的任务。

在Android上,您需要提供有效的图标图像(在/ src / Android / RES下),并且必须禁用AndroidManifest文件中的调试选项:在应用程序标记下,添加

Android :可调试= '假'。最后,您必须签署应用程序

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


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

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

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