我需要在我的 GWT 应用程序中进行一些客户端 2D 绘图(没什么花哨的,只是绘制一堆基本的 2D 形状 - 圆形、矩形等)。
我不相信 GWT 有图形/绘图框架,所以我想知道是否有任何方法可以使用 JSNI以某种方式连接到著名的 Raphael JS 库并从 GWT 内部调用 Raphael。
如果这是不可能的,有人可以解释为什么以及我的选择是什么?
如果这是可能的,请考虑以下绘制正方形的 Raphael 代码:
paper = new Raphael(0,0,500,500);
var rect = paper.rect(x,y,width,height).attr({"fill":"white","stroke":"red"});
我希望当用户单击按钮时执行上面的 JS 代码。这是我的 GWT 点击处理程序:
@UiHandler("signInButton")
void onClickSignInButton(final ClickEvent clickEvent) {
// ????
}
如何连接两者?
最佳答案
将 Raphael 类包装在 JSObject 类中。
public final RaphaelJSO {
protected RaphaelJSO(){}
public static RaphaelJSO getNew(float a, float b, float c, float d){
return getNewInner(a,b,c,d);
}
private native static RaphaelJSO getNewInner(float a, float b, float c, float d)/*-{
return new Raphael(a, b, c, d);
}-*/;
public JSObject circle(int a,int b, int c){
return circle(this,a,b,c);
}
private native JSObject circle(RaphaelJSO o, int a, int b, int c)/*-{
return o.circle(a,b,c);
}-*/;
}
同样,您可以包装其他类和/或为其提供方法。
然后按照其他方式调用此 Java 代码。
关于java - GWT 可以通过 JSNI 使用 Raphael 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20442090/