0
如何将Java(JavaFx)中的变量传递给JavaScript?我想我必须使用executeScript
,但我不确定如何真正使用它。基本上我想发送元件在arraylist
从Java到在JavaScript中array
的程序。下面的代码是我写的Java代码。希望有人能帮助我。先谢谢你。如何将JavaFX之间的变量传递给javaScript?
import java.util.ArrayList;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class UserInterface extends Application{
Button btn_js;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
WebView myWebView = new WebView();
WebEngine engine = myWebView.getEngine();
ArrayList<String> arr = new ArrayList<String>();
btn_js = new Button("fire js");
btn_js.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
//engine.executeScript("something goes here to transfer data to js");
}
});
VBox root = new VBox();
root.getChildren().addAll(myWebView, btn_js);
Scene scene = new Scene(root, 500, 500);
stage.setScene(scene);
stage.show();
}
}
谢谢DVarga。我会按照你的榜样,使我的工作方案。 – zxc34