'. '

MigrateFromGWT

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(New page: GWT has a lot of drawbacks which Bck2Brwsr project addresses by being a real JVM. As such there is a value in migrating to this new system. Moreover the [[Mi...)
Line 23: Line 23:
}
}
-
@net.java.html.js.JavaScriptBody(args = {"r", "time"}, javacall = true, body =
+
public static native void later(Runnable r, int time) /*-{
-
" window.setTimeout(function() {\n" +
+
window.setTimeout(function() {
-
" r.@java.lang.Runnable::run()();\n" +
+
r.@java.lang.Runnable::run()();
-
" }, time);\n" +
+
}, time);
-
"")
+
}-*/;
-
public static native void later(Runnable r, int time);
+
-
@net.java.html.js.JavaScriptBody(args = {"html"}, body =
+
public static native void html(String html) /*-{
-
" var b = document.getElementsByTagName(\"body\")[0];\n" +
+
var b = document.getElementsByTagName("body")[0];
-
" b.innerHTML = html;\n" +
+
b.innerHTML = html;
-
" ")
+
}-*/;
-
public static native void html(String html);
+
-
@net.java.html.js.JavaScriptBody(args = {"msg"}, body =
+
public static native void alert(String msg) /*-{
-
" alert(msg);\n" +
+
alert(msg);
-
" ")
+
}-*/;
-
public static native void alert(String msg);
+
-
@net.java.html.js.JavaScriptBody(args = {"id", "r"}, javacall = true, body =
+
public static native void onClick(String id, Runnable r) /*-{
-
" document.getElementById(id).onclick = function() {\n" +
+
document.getElementById(id).onclick = function() {
-
" r.@java.lang.Runnable::run()();\n" +
+
r.@java.lang.Runnable::run()();
-
" };\n" +
+
};
-
"")
+
}-*/;
-
public static native void onClick(String id, Runnable r);
+
}
}
</source>
</source>

Revision as of 16:54, 29 January 2014

GWT has a lot of drawbacks which Bck2Brwsr project addresses by being a real JVM. As such there is a value in migrating to this new system. Moreover the migration is quite easy. Let me give you a demo.

GWT Project

The primary focus right now is to show that the GWT Java to JavaScript native interface methods can easily be migrated to real HotSpot virtual machine. Imagine following application that talks directly to JavaScript in the browser:

public class ButtonApp implements Runnable {
 
   public static void onLoad() {
        alert("Initializing...");
        html("<button id='x'>Click me!</button>");
        onClick("x", new Runnable() {
            public void run() {
                alert("Button was clicked!");
                later(new ButtonApp(), 1000);
            }
        });
    }
 
    public void run() {
        alert("One second after that!");
    }
 
  public static native void later(Runnable r, int time) /*-{
        window.setTimeout(function() {
            r.@java.lang.Runnable::run()();
        }, time);
    }-*/;
 
    public static native void html(String html) /*-{
        var b = document.getElementsByTagName("body")[0];
        b.innerHTML = html;
    }-*/;
 
    public static native void alert(String msg) /*-{
       alert(msg);
    }-*/;
 
    public static native void onClick(String id, Runnable r) /*-{
       document.getElementById(id).onclick = function() {
        r.@java.lang.Runnable::run()();
       };
    }-*/;
 
}
Personal tools
buy