在 GWT 中导入枚举
我有以下代码。
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);
}
}
但它向我显示了这个错误:
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);
但我在互联网上看到可以这样声明PCT。我应该导入一些附加标头还是该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您忘记导入 PCT。
You've forgotten to import PCT.
您应该进行静态导入:
但是就像我在评论中提到的那样 - 恕我直言,最好明确引用枚举 - 至少当它们的名称很短时;)
You should do a static import:
But like I mentioned in the comment - it's better IMHO to explicitly refer to enums - at least when their names are short ;)