开发者

Importing enums in GWT

I have the following code.

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.Widget;

public class LayoutPanelExample implements EntryPoint{
    @Override
     public void onModuleLoad() {
         Widget childone = new HTML("left"),childtwo=new HTML("right");
         LayoutPanel p = new LayoutPanel();
         p.add(childone);开发者_开发技巧
         p.add(childtwo);
         p.setWidgetLeftWidth(childone, 0, PCT, 50, PCT);
         p.setWidgetRightWidth(childtwo, 0, PCT, 50, PCT);
         RootLayoutPanel rp = RootLayoutPanel.get();
         rp.add(p);
     }
}

But it shows me this error:

C:\XAMPP\xampp\htdocs\LayoutPanelExample\src\java\LayoutPanelExample.java:19: cannot find symbol
symbol  : variable PCT
location: class LayoutPanelExample
     p.setWidgetLeftWidth(childone, 0, PCT, 50, PCT);

But I have seen on the Internet that it is possible to declare PCT like this. Should I import some addition header or what to do?


You've forgotten to import PCT.

import static com.google.gwt.dom.client.Style.Unit.PCT;


You should do a static import:

import static com.google.gwt.dom.client.Style.Unit.*;

But like I mentioned in the comment - it's better IMHO to explicitly refer to enums - at least when their names are short ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜