新GWT应用程序中的按钮

时间:2012-04-03 13:37:58

标签: java gwt

我刚开始使用GWT。我给出了here的教程。但是当我创建新项目并在水平面板中添加两个按钮然后在RootPanel中时,它只显示了我在HTML文件中创建的标题。你能告诉我可能是什么原因吗? 这是Java类,HTML和XML: Java类:

    package org.elsys.salvation.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;


public class Salvation implements EntryPoint {

    private Button newData = new Button("New");
    private Button existingData = new Button("Existing");
    private HorizontalPanel mainHorizontalPanel = new HorizontalPanel();
    private Label lastUpdatedLabel = new Label();

    public void onModuleLoad() {
        mainHorizontalPanel.add(newData);
        mainHorizontalPanel.add(existingData);
        mainHorizontalPanel.add(lastUpdatedLabel);

        RootPanel.get("Salvation").add(mainHorizontalPanel);
    }

}

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="Salvation.css">
        <title>Diploma Defences Organiser</title>
        <script type="text/javascript" language="javascript" src="stockwatcher/stockwatcher.nocache.js"></script>
    </head>
    <body>

        <h1>Diploma Defences Organiser</h1>
        <div id="Salvation"></div>
        <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
        <noscript>
            <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
            Your web browser must have JavaScript enabled
            in order for this application to display correctly.
            </div>
        </noscript>
    </body>
</html>

和XML:

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='Salvation'>
  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name='com.google.gwt.user.User'/>

  <!-- Inherit the default GWT style sheet.  You can change       -->
  <!-- the theme of your GWT application by uncommenting          -->
  <!-- any one of the following lines.                            -->
  <inherits name='com.google.gwt.user.theme.clean.Clean'/>
  <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->

  <!-- Other module inherits                                      -->

  <!-- Specify the app entry point class.                         -->
  <entry-point class='org.elsys.salvation.client.Salvation'/>

  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>

</module>

2 个答案:

答案 0 :(得分:0)

检查此行是否正确:

<script type="text/javascript" language="javascript" src="stockwatcher/stockwatcher.nocache.js"></script>

我认为你应该有:Salvation/Salvation.nocache.js作为脚本标记的来源。

答案 1 :(得分:0)

在您选择的浏览器中打开开发者控制台。您应该能够跟踪所做的Web请求。确保调用了* nocache.js文件并返回正常状态(状态200)。

如果确实有效,那么其他任何明显的事情都不会突然冒出来。也许尝试不指定要加载的div?

RootLayoutPanel.get().add(mainHorizontalPanel);