GWT实施

时间:2010-09-03 12:44:49

标签: gwt

我有以下代码

package org.david.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.logical.shared.BeforeSelectionEvent;
import com.google.gwt.event.logical.shared.BeforeSelectionHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.TabBar;
public class TabBar1  implements EntryPoint{
    @Override
    public void onModuleLoad(){
        TabBar bar=new TabBar();
        bar.addTab("foo");
        bar.addTab("bar");
        bar.addTab("baz");
         bar.addSelectionHandler(new SelectionHandler(){

             public void onSelection(SelectionEvent event){
                 //let user know what you just did
                 Window.alert("you clicked tab"+event.getSelectedItem());
             }

         });
        // Just for fun, let's disallow selection of 'bar'.
         bar.addBeforeSelectionHandler(new BeforeSelectionHandler() {
          public void onBeforeSelection(BeforeSelectionEvent event) {
       if (event.getItem().intValue() == 1) {
          event.cancel();
                }
            }


         });

    }
}

但我有以下错误

ompiling 1 source file to C:\XAMPP\xampp\htdocs\TabBar1\build\web\WEB-INF\classes
C:\XAMPP\xampp\htdocs\TabBar1\src\java\org\david\client\TabBar1.java:28: cannot find symbol
symbol  : method intValue()
location: class java.lang.Object
       if (event.getItem().intValue() == 1) {
Note: C:\XAMPP\xampp\htdocs\TabBar1\src\java\org\david\client\TabBar1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
C:\XAMPP\xampp\htdocs\TabBar1\nbproject\build-impl.xml:518: The following error occurred while executing this line:
C:\XAMPP\xampp\htdocs\TabBar1\nbproject\build-impl.xml:248: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)

请帮助

1 个答案:

答案 0 :(得分:4)

BeforeSelectionEvent应为BeforeSelectionEvent<Integer>,以便getItem()返回Integer而不是Object

Object没有intValue()方法,Integer也没有。

你应该在编译中看到一个未经检查的转换警告,说明了这一点。