So this is the code that runs the application:
public class TestJavaFX extends Application {
private Scene scene;
@Override
public void start(Stage stage) throws UnsupportedEncodingException, IOException {
// create the scene
stage.setMinWidth(550);
stage.setMinHeight(400);
stage.setTitle("Dashboard Loading...");
WebView browser = new WebView();
// sets temp title of scene & creates WebView, a JavaFX panel
// Programmatic capabilities (aka DOM/loading pages) are accessed
// through the WebEngine (browser.getEngine())
browser.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
JSObject win = (JSObject) browser.getEngine().executeScript("window");
win.setMember("app", new JavaApp());
HTMLDocument doc = (HTMLDocument) browser.getEngine().getDocument();
stage.setTitle(doc.getTitle());
}
}
});
// adds listener to add app object (from java) to the javascript
// allowing javascript access to java functions
// and also changes the window title to the HTML title
browser.getEngine().load(getClass().getResource("html/index.htm").toString());
// loads the page, resource is configured to run in a jar setting as
// well as in the IDE
StackPane layout = new StackPane();
layout.getChildren().add(browser);
// creates a layout for the scene and adds the webview
scene = new Scene(layout, 900, 650);
new JavaApp().runBatch(5050505);
// initiates the scene (AKA the inner part of the window) and adds a
// layout
// numbers can be changed; they are the size of the window (W,H)
stage.setScene(scene);
stage.show();
// adds scene to stage (window part of window)
// packs stage and makes stage visible
}
public static void main(String[] args) {
launch(args);
}
And here is the code for the JavaApp class:
public class JavaApp{
public void runBatch(int num) /*throws IOException*/ {
System.out.println(num);
}
}
The HTML file calls runBatch by a button which has an onclick attribute ="app.runBatch(number)" where number could be 0, 1, 2, etc.
Here's the problem: I have no idea why, but whenever runBatch has an argument (e.g. int num) in its definition, it's as if the function doesn't even exist to the webpage and it doesn't run when I click the HTML button. As soon as I remove the argument, it runs fine. Is this a bug or is it something I can fix?