2012-03-18 79 views
1

我是GWT的初學者。我想到了我的入門級如下:從eclipse執行GWT應用程序

public class HelloWorld implements EntryPoint { 


public void onModuleLoad() { 
    // TODO Auto-generated method stub 
    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"); 
     } 

    }); 

    try{ 
    RootPanel.get("hold").add(label); 
    RootPanel.get("hold").add(button); 
    }catch(Exception e){ 
     System.out.println(e.toString()); 
    } 
} 

} 

和XML文件來聲明入門級爲:

<?xml version="1.0" encoding="UTF-8"?> 
<module rename-to='testgwt'> 
    <inherits name='com.google.gwt.user.User'/> 
    <inherits name='com.google.gwt.user.theme.clean.Clean'/> 
    <!-- Specify the app entry point class --> 
    <entry-point class="com.jade.testgwt.client.HelloWorld"/> 
</module> 

HTML文件如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 

<html> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <link type="text/css" rel="stylesheet" href="TestGWT.css"> 
    <title>My First GWT applicaton</title> 
    <script type="text/javascript" language="javascript" src="testgwt/test_gwt.nocache.js"></script> 
    </head> 

    <body> 
    <h1>My First GWT applicaton</h1> 
    <div id="hold"></div> 

    </body> 
</html> 

所以當我通過右鍵單擊該項目並選擇Run as Web應用程序運行時,我期待看到網頁上的標籤和按鈕控件。我只能看到h1的標籤文本。不知道爲什麼標籤和按鈕不顯示?

回答

1

相反的RootPanel.get("hold").add(...),試試這個:

RootLayoutPanel.get().add(label); 
RootLayoutPanel.get().add(button); 
+0

沒有解決問題。 – jade 2012-03-18 14:14:25

0

什麼是你的GWT模塊的全名?如果模塊名稱爲testgwt,我不認爲test_gwt.nocache.js是正確的。嘗試刪除下劃線。無論如何,您可以在Firefox中安裝Firebug來監視網絡活動,並查看獲取JS的請求是否失敗。

編輯:如果您在Eclipse中創建了「新建Web應用程序」項目,則會生成一個工作示例應用程序,您可以將其與您的代碼進行比較。

+0

酷!沒有看到。非常感謝,謝謝。 – jade 2012-03-18 14:15:09

0

你需要拿面板。並在該面板中添加您的標籤和按鈕。

該面板將被添加到RootPanel.get(「hold」).add(...)中。

0

你HTML中的ID 分工如下頁面添加此行「持有」

<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position: absolute; width: 0; height: 0; border: 0"></iframe> 

你錯過了這條線。

還可以編輯腳本代碼在HTML頁面的,

確保一個testgwt.nocache.jstestgwt文件夾下存在

相關問題