DLH*_*DLH 10 javascript java gwt native
我在我的一个GWT Java类中有一个本机Javascript方法,但是我无法从本机Javascript代码调用我的Java方法.我试图尽可能地密切关注这一点,但我无法让它发挥作用.我编译并在Firefox中运行它,错误控制台说"错误:this.lc不是函数".我尝试将所有方法改为公开,但这似乎没有什么区别.我究竟做错了什么?
package com.proprintsgear.design_lab.client;
...
public class ValueBox extends HorizontalPanel {
...
private void fireChange() {
...
}
private void increaseValue() {
...
}
private native void addNativeMouseWheelListener(String id) /*-{
function mouseOverHandler(e) {
$wnd.addEventListener("DOMMouseScroll", scrollWheelMove, false);
}
function mouseOutHandler(e) {
$wnd.removeEventListener("DOMMouseScroll", scrollWheelMove, false);
}
function scrollWheelMove(e) {
if ($wnd.event || $wnd.Event) {
if (!e) e = $wnd.event;
if (e.wheelDelta <= 0 || e.detail > 0 ) {
$wnd.alert("DOWN");
} else {
this.@com.proprintsgear.design_lab.client.ValueBox::increaseValue()();
}
this.@com.proprintsgear.design_lab.client.ValueBox::fireChange()();
}
}
var box=$doc.getElementById(id);
box.addEventListener("mouseout",mouseOutHandler,false);
box.addEventListener("mouseover",mouseOverHandler,false);
}-*/;
Run Code Online (Sandbox Code Playgroud)
rus*_*elf 12
在我过去所做的所有代码中,我从未使用'this'来识别我的课程,我已经通过了课程.
例如:改变这个:
private native void addNativeMouseWheelListener(String id) /*-{
function mouseOverHandler(e) {
$wnd.addEventListener("DOMMouseScroll", scrollWheelMove, false);
}
function mouseOutHandler(e) {
$wnd.removeEventListener("DOMMouseScroll", scrollWheelMove, false);
}
function scrollWheelMove(e) {
if ($wnd.event || $wnd.Event) {
if (!e) e = $wnd.event;
if (e.wheelDelta <= 0 || e.detail > 0 ) {
$wnd.alert("DOWN");
} else {
this.@com.proprintsgear.design_lab.client.ValueBox::increaseValue()();
}
this.@com.proprintsgear.design_lab.client.ValueBox::fireChange()();
}
}
var box=$doc.getElementById(id);
box.addEventListener("mouseout",mouseOutHandler,false);
box.addEventListener("mouseover",mouseOverHandler,false);
}-*/;
Run Code Online (Sandbox Code Playgroud)
对此:
private native void addNativeMouseWheelListener(ValueBox instance, String id) /*-{
function mouseOverHandler(e) {
$wnd.addEventListener("DOMMouseScroll", scrollWheelMove, false);
}
function mouseOutHandler(e) {
$wnd.removeEventListener("DOMMouseScroll", scrollWheelMove, false);
}
function scrollWheelMove(e) {
if ($wnd.event || $wnd.Event) {
if (!e) e = $wnd.event;
if (e.wheelDelta <= 0 || e.detail > 0 ) {
$wnd.alert("DOWN");
} else {
instance.@com.proprintsgear.design_lab.client.ValueBox::increaseValue()();
}
instance.@com.proprintsgear.design_lab.client.ValueBox::fireChange()();
}
}
var box=$doc.getElementById(id);
box.addEventListener("mouseout",mouseOutHandler,false);
box.addEventListener("mouseover",mouseOverHandler,false);
}-*/;
Run Code Online (Sandbox Code Playgroud)