Java(JavaFx)からJavaScriptに変数を渡すにはどうすればよいですか?私はexecuteScript
を使用しなければならないと思うが、実際にどのように使用するのかは分からない。基本的に私はarraylist
の要素をjavaからarray
にjavaScriptで送信するプログラムにしたいと思います。以下のコードは、私が書いた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