Forum Stats

  • 3,839,099 Users
  • 2,262,455 Discussions
  • 7,900,863 Comments

Discussions

How does a JavaFX applet communicate with the browser?

pron
pron Member Posts: 3
edited Aug 4, 2011 11:06AM in JavaFX 2.0 and Later
How does a JavaFX applet communicate with it containing browser, in general, and with the DOM on its containing page in particular?
Tagged:

Answers

  • shakir.gusaroff
    shakir.gusaroff Member Posts: 689 Gold Badge
    Adding HTML Content to JavaFX Applications tutorial is located here: http://download.oracle.com/javafx/2.0/webview/jfxpub-webview.htm
  • aidreamer
    aidreamer Member Posts: 242
    edited May 30, 2011 1:22PM
    If by that you mean, how does an applet modify the page it is on, doing things the Java way is described here: http://www.oracle.com/technetwork/java/javase/plugin2-142482.html

    Here is an example of how to retrieve an object representing the page. It should be modifiable:
    import com.sun.java.browser.plugin2.DOM;
    
    public class Main extends JApplet {
        public void doSomething() throws Exception {
            //Get the document
            HTMLDocument document = (HTMLDocument)DOM.getDocument(this);
        }
    }
    Bear in mind that not all browsers support this functionality.

    This isn't exactly up to date, but a JavaFX way is located here: http://download.oracle.com/javafx/1.2/tutorials/javafx-javascript/index.html . I don't know how the new JavaFX plugin will effect things, but it might not currently be possible for a JavaFX 2.0 applet just yet.
  • pron
    pron Member Posts: 3
    edited May 30, 2011 5:33PM
    Well, you could use the plugin2 API, but for that you need to pass in an instance of Applet, which would load AWT. How will that be done in the new prism plugin?

    Edited by: user9048615 on May 30, 2011 2:23 PM

    Edited by: user9048615 on May 30, 2011 2:31 PM
  • aidreamer
    aidreamer Member Posts: 242
    Who knows? Maybe you should make a request for enhancement at [url http://javafx-jira.kenai.com/]jira.
  • 865172
    865172 Member Posts: 34
    Don't tried yet, but with Applets was possible to comunicate with browser with external jar containing JSObject.
    It's an implementation in JavaFX 2.0 :
    javafx.scene.web.JSObject, so try to play with it and hope it work
  • 874685
    874685 Member Posts: 12
    I'm trying to go the other way, and send strings from javascript on a webpage to the JavaFX app embedded on the page. This was fairly simple with FX 1.3, where I could just implement a CustomNode and make direct calls with the javascript objects provided by fx.
    <script src="http://dl.javafx.com/1.3/dtfx.js"></script>
    <script>
    javafx(
      {
        archive: "myapplet.jar",
        width: 515,
        height: 414,
        code: "com.my.project.app",
        id: "app"
      }
    );
    
    app.script.MyApp.msgReceived("a string of some sort");
    </script>
    But the deployJava.javafx() call doesn't appear to provide this same functionality. How I take the result of the javafx() call and communicate with the object it creates?
This discussion has been closed.