Java 如何使用jfxmobile插件,例如磁强计服务
我想使用一些“gluonhq魅力下降”服务,比如磁强计 我不明白为什么磁强计服务不能导入到我的Java类文件中。错误消息是 “无法解析导入com.glionhq.charm.down.plugins.accelerator” 以前,在EclipseNeon2-Help-Available软件站点中,我安装了e(fx)clipse。您可以在安装详细信息中看到:Java 如何使用jfxmobile插件,例如磁强计服务,java,eclipse-plugin,gluon,javafxports,efxclipse,Java,Eclipse Plugin,Gluon,Javafxports,Efxclipse,我想使用一些“gluonhq魅力下降”服务,比如磁强计 我不明白为什么磁强计服务不能导入到我的Java类文件中。错误消息是 “无法解析导入com.glionhq.charm.down.plugins.accelerator” 以前,在EclipseNeon2-Help-Available软件站点中,我安装了e(fx)clipse。您可以在安装详细信息中看到: "e(fx)clipse - IDE - Update site" with http://download.eclipse.org/e
"e(fx)clipse - IDE - Update site" with http://download.eclipse.org/efxclipse/updates-released/2.4.0/site
注意:我已经安装了GluonTools 2.4.0,包括e(fx)mobile IDE 2.3.0。以下是我的项目的build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:2.4.0'
}
}
plugins {
id "com.github.hierynomus.license" version "0.13.1"
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.GluonApplication'
jfxmobile {
downConfig {
version '4.0.0'
plugins 'accelerometer', 'compass', 'device', 'orientation', 'storage', 'vibration', 'display', 'lifecycle', 'statusbar', 'position'
}
android {
applicationPackage = 'com.gluonapplication'
manifest = 'src/android/AndroidManifest.xml'
androidSdk = 'C:/Users/pascal/AppData/Local/Android/sdk'
resDirectory = 'src/android/res'
compileSdkVersion = '23'
buildToolsVersion = '25.0.1'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
}
}
以下是在Eclipse上创建安装了Gluon插件2.4.0的应用程序的步骤 1。使用IDE插件 单击新建,选择Glon->Glon Mobile-单视图项目,填写所需数据(项目名称、包等),单击完成 2。查看build.gradle文件 打开构建文件,并更新版本:jfxmobile插件版本为1.3.2。胶子魅力是4.3.0,胶子羽绒使用3.2.0 3。添加您的下载插件 将磁强计插件添加到
downConfig
这应该是build.gradle文件(主类名除外):
请注意,您不需要添加任何进一步的插件依赖项,downConfig
会为您添加插件依赖项
4。将服务添加到基本视图中
这是磁强计服务的一个简单用例:
package com.gluonhq.magnetometer;
import com.gluonhq.charm.down.Services;
import com.gluonhq.charm.down.plugins.MagnetometerService;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.Icon;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
public class BasicView extends View {
public BasicView(String name) {
super(name);
Label label1 = new Label();
Label label2 = new Label();
Button button = new Button("Start Magnetometer");
button.setGraphic(new Icon(MaterialDesignIcon.VIBRATION));
button.setOnAction(e ->
Services.get(MagnetometerService.class)
.ifPresent(s -> s.readingProperty()
.addListener((obs, ov, nv) -> {
label1.setText(String.format("X: %.4f Y: %.4f Z: %.4f\n Mag: %.4f", nv.getX(), nv.getY(), nv.getZ(), nv.getMagnitude()));
label2.setText(String.format("Yaw: %.2f\u00b0 Pitch: %.4f\u00b0 Roll: %.4f\u00b0", Math.toDegrees(nv.getYaw()),
Math.toDegrees(nv.getPitch()), Math.toDegrees(nv.getRoll())));
})));
VBox controls = new VBox(15.0, button, label1, label2);
controls.setAlignment(Pos.CENTER);
setCenter(controls);
}
@Override
protected void updateAppBar(AppBar appBar) {
appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> System.out.println("Menu")));
appBar.setTitleText("Magnetometer");
}
}
5。桌面测试
使用Gradle任务窗口,选择application->run
请注意,该服务在桌面上不可用,并且无法工作,但您将检查应用程序的运行情况,不会出现错误
6。在Android上部署
使用Gradle任务窗口,选择other->androidInstall
在运行任务之前,请先插入手机。如果一切正常,您应该能够在设备上测试应用程序:
您不是已经在Eclipse上安装了Gluon IDE插件吗??转到文件->新建->项目。。。你看到胶子文件夹了吗?你不需要安装jfxmobile插件,我在安装Eclipse时也遇到过一些问题,有时候速度会非常慢。您尝试过NetBeans吗?右键单击项目根目录或build.gradle文件本身,选择gradle,然后刷新gradle项目。还有其他插件解决了,所以加速度计和磁强计也将解决。否则,请关闭Eclipse并再次打开它,以便项目得到刷新。请确保已使用我的答案中的代码更新了build gradle和BasicView。然后您只需运行
gradlew clean build run
即可使其正常工作,或者从Gradle tasks视图中选择任务clean、build和run。如果您有错误,请发布它。确保您可以使用常规依赖项,如编译com.gloonhq:charm down plugin compass:3.2.0',等等。不需要手动下载。但准确地说,这就是downConfig
为您所做的,这就是为什么命令行为您工作的原因。因此,这是IDE配置错误的一种情况。至于语法,你的意思是什么?请参阅上面的代码,我使用磁强计服务
。
package com.gluonhq.magnetometer;
import com.gluonhq.charm.down.Services;
import com.gluonhq.charm.down.plugins.MagnetometerService;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.Icon;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
public class BasicView extends View {
public BasicView(String name) {
super(name);
Label label1 = new Label();
Label label2 = new Label();
Button button = new Button("Start Magnetometer");
button.setGraphic(new Icon(MaterialDesignIcon.VIBRATION));
button.setOnAction(e ->
Services.get(MagnetometerService.class)
.ifPresent(s -> s.readingProperty()
.addListener((obs, ov, nv) -> {
label1.setText(String.format("X: %.4f Y: %.4f Z: %.4f\n Mag: %.4f", nv.getX(), nv.getY(), nv.getZ(), nv.getMagnitude()));
label2.setText(String.format("Yaw: %.2f\u00b0 Pitch: %.4f\u00b0 Roll: %.4f\u00b0", Math.toDegrees(nv.getYaw()),
Math.toDegrees(nv.getPitch()), Math.toDegrees(nv.getRoll())));
})));
VBox controls = new VBox(15.0, button, label1, label2);
controls.setAlignment(Pos.CENTER);
setCenter(controls);
}
@Override
protected void updateAppBar(AppBar appBar) {
appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> System.out.println("Menu")));
appBar.setTitleText("Magnetometer");
}
}