我制作了一个在PC上运行良好的Javafx应用程序。现在,我尝试将其转移到Android智能手机。为此,我使用JavaFXPorts(Gluon),Eclipse和Gradle。
现在,我遇到了一个非常简单的例子:
void showPopUp() {
Button button = new Button("Action do do"));
HBox.setMargin(button , new Insets(10, 30, 10, 30));
button .setOnAction(e -> {
actionToDo();
});
Scene scene = new Scene (button, 100, 200);
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.setScene(scene);
stage.show();
}
你知道原因吗?
以下是 整个代码 :
定期任务(工作正常)
延迟任务(工作正常)
显示模式PopUp的按钮“btn”。它上面的touchScreen工作正常,允许转到PopUp
带有2个按钮的PopUp boutonPopUpA和boutonPopUpB添加到HBOX boutonsMenuPrincipal
以及其场景“连接到”boutonsMenuPrincipal的舞台
在popUp中,显示boutonPopUpA和boutonPopUpB但不活动(触摸屏上没有生成的跟踪)
package com.gluonapplication;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class GluonApplication extends Application {
private int nbAppuiToucheSetOnAction = 0;
private int nbAppuiTouchePopUp = 0;
static long BDTapplication = 110;
static long nbBDT = 0;
static long t0 = System.currentTimeMillis();
/********************************************************/
public static void periodicProcessing(String str) {
nbBDT++;
traceWithSystemTime("periodicProcessing of " + str + " / nbBDT: " + nbBDT);
}
/********************************************************/
public static void traceWithSystemTime(String comments) {
long t = System.currentTimeMillis();
long deltaT =t - t0;
System.out.println("time - t0: " + t0 + " / t: "+ t + " / detaT: " + deltaT + " ms --- " + comments);
}
/********************************************************/
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World sur Android! ");
// A PERIODIC TASK
Runnable runnable = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
for (int i=0; i < 10; i++) {
periodicProcessing("timer plus");
}
}
};
final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
service.scheduleAtFixedRate(runnable, 0, BDTapplication, TimeUnit.MILLISECONDS);
// A DELAYED TASK
int TASK_DELAY = 1000; // ms
TimerTask task = new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i < 10; i++) {
periodicProcessing("timer task done");
}
}
};
new Timer().schedule(task, TASK_DELAY);
AnchorPane root = new AnchorPane();
root.setVisible(true);
Scene scene = new Scene(root);
// *********************** Button
// btn works fine
Button btn = new Button();
btn.setText("setOnAction 1");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
nbAppuiToucheSetOnAction++;
traceWithSystemTime("SETonACTION: nbAppui = "+ nbAppuiToucheSetOnAction);
showPopUpMenuPrincipal();
}
});
HBox.setMargin(btn, new Insets(10, 30, 10, 30));
VBox zoneBtn= new VBox();
VBox.setMargin(zoneBtn, new Insets(30, 5, 1, 10));
zoneBtn.getChildren().add( btn);
zoneBtn.setAlignment(Pos.CENTER);
root.getChildren().addAll(zoneBtn);
primaryStage.setTitle("Title");
// ************************************* DISPLAY
root.requestFocus();
primaryStage.setScene(scene);
primaryStage.setTitle("Test4");
primaryStage.setFullScreen(true);
primaryStage.show();
traceWithSystemTime("End of test");
}
/*************************************/
void showPopUpMenuPrincipal(){
traceWithSystemTime("Beginning of showPopUpMenuPrincipal");
Button boutonPopUpA = new Button("setOnAction 2a");
boutonPopUpA.setOnAction(e-> {
nbAppuiTouchePopUp++;
traceWithSystemTime("Action sur setOnAction 2a: nbAppui: " + nbAppuiTouchePopUp);
});
Button boutonPopUpB = new Button("setOnAction 2b");
boutonPopUpB.setOnAction(e-> {
nbAppuiTouchePopUp++;
traceWithSystemTime("Action sur setOnAction 2b: nbAppui: " + nbAppuiTouchePopUp);
});
HBox.setMargin(boutonPopUpA, new Insets(10, 30, 10, 30));
VBox zonePopUp= new VBox();
VBox.setMargin(zonePopUp, new Insets(30, 5, 1, 10));
zonePopUp.getChildren().add( boutonPopUpA);
zonePopUp.setAlignment(Pos.CENTER);
Stage stagePopUpMenu = new Stage();
stagePopUpMenu.setTitle("Title");
stagePopUpMenu.initModality(Modality.APPLICATION_MODAL);
HBox boutonsMenuPrincipal = new HBox();
boutonsMenuPrincipal.setAlignment(Pos.CENTER);
boutonsMenuPrincipal.getChildren().addAll( zonePopUp, boutonPopUpB);
Scene sceneMenu = new Scene(boutonsMenuPrincipal, 400, 250);
stagePopUpMenu.setOpacity(0.8);
stagePopUpMenu.setResizable(false);
stagePopUpMenu.setScene(sceneMenu);
stagePopUpMenu.show();
traceWithSystemTime("End of showPopUpMenuPrincipal");
}
}
我的构建gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b10'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
}
mainClassName = 'com.gluonapplication.GluonApplication'
jfxmobile {
android {
applicationPackage = 'com.gluonapplication'
manifest = 'src/android/AndroidManifest.xml'
androidSdk = 'C:/Users/pascal/AppData/Local/Android/sdk'
resDirectory = 'src/android/res'
compileSdkVersion = '23'
buildToolsVersion = '22.0.1'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
}
}
答案 0 :(得分:0)
您需要更新jfxmobile插件版本。自1.0.0-b10版本(一年半以前)以来,已修复和更新了许多内容。
目前version是1.3.2。它不仅是插件,而且主要是插件包含的javafxports version。
如果您在自己喜欢的IDE上使用Gluon插件,选择单视图项目,您将获得最小的项目模板和有效的build.gradle
文件。
这是一个更新的构建脚本:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonhq.testtouch.TestTouch'
dependencies {
compile 'com.gluonhq:charm:4.3.0'
}
jfxmobile {
downConfig {
version = '3.2.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
}
您可以将所有代码添加到BasicView,在移动设备上进行部署并对其进行测试。
我刚刚完成它并且一切正常:任务运行得很快,按钮响应很快。
使用JavaFXPorts不建议创建第二个Stage
。您可以使用Dialog
(内置JavaFX对话框或Gluon Mobile对话框)。
您可以免费测试Gluon Mobile库,启动时只能获得一个唠叨屏幕。
无论如何,您可以删除Gluon Mobile库(只需从依赖项中删除com.gluonhq:charm:4.3.0
),然后您必须将MobileApplication
移回常规JavaFX Application
并删除BasicView上课(大部分和你现在一样)。