我开始使用 gwt,我不明白为什么我的应用程序无法显示任何按钮,即使在我的代码中我已经指示要创建一个按钮。
我的入口点类是
package com.france.webapp.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
public class MyEntryPoint implements EntryPoint {
public MyEntryPoint(){
}
@Override
public void onModuleLoad() {
Label label = new Label("Hello GWT !!!");
Button button = new Button("Say something");
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("Hello, again");
}
});
RootPanel.get().add(label);
RootPanel.get().add(button);
}
}
我在使用最新版本的 jdk 和 eclipse juno 的 Windows 上。我的应用程序运行并显示了 html 页面,但没有按钮。我已经使用最新版本的 chrome 和 firefox 20 以及 gwt 开发插件对其进行了测试。
我必须编译项目还是运行方式 -> Web 应用程序选项足以显示按钮?我的 gwt.xml 看起来不错,我正在关注http://www.vogella.com/articles/GWT/article.html上的教程
这是我的 MyModule.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.google.gwt.user.User" />
<source path="client" />
<entry-point class="com.france.webapp.client.MyEntryPoint"></entry-point>
</module>
我的 html.html 文件
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>html</title>
<script type="text/javascript" language="javascript" src=".nocache.js"></script>
</head>
<body>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
</body>
</html>
我查看了 eclipse 控制台,这就是它的内容
[WARN] 404 - GET /.nocache.js (127.0.0.1) 1397 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Referer: http://127.0.0.1:8888/html.html?gwt.codesvr=127.0.0.1:9997