I am new relatively new to using JSNI in GWT, just wanted to know whether its possible to create a DOM elelment using JSNI? I have tried to use the following:

private class myImageElement extends ImageElement {

    private boolean inUse = false;

    protected myImageElement() {}

    public final native void setIfinUse(boolean check) /*-{this.inUse=check}-*/ ;

    public final native boolean checkIfinUse() /*-{return this.inUse}-*/ ;
}

Now the code to create an object of myImageElement would be:

private native myImageElement get() /*-{ what should be here } -*/

Since I didnt not find anyway to create it using JSNI, can anybody please let me know whether I am doing it correctly or not?

有帮助吗?

解决方案

You can create it with the Document class of GWT and cast the Element to your new Element class.

 myImageElement element =(myImageElement) Document.get().createImageElement();

But, in GWT all *Elementclasses are a method as for doing the cast :

 public static myImageElement as(Element elem) {
   assert elem.getTagName().equalsIgnoreCase("img");
   return (myImageElement) elem;
 }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top