windowbuilder教程不起作用

时间:2012-03-06 05:20:38

标签: gwt windowbuilder

我正在尝试做一个教程,允许人们添加和删除股票,并见证他们的价格和变化。本教程演示了如何使用GUI构建器GWT Designer基于GWT教程创建和设计Stock Watcher应用程序。

http://code.google.com/webtoolkit/tools/gwtdesigner/tutorials/stockwatcher.html#design_ui

到目前为止,我有SW.java:

package edu.gatech.client;
import java.util.ArrayList;

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.event.dom.client.KeyCodes;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.dom.client.KeyPressEvent;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class SW implements EntryPoint {
    private RootPanel rootPanel;
    private FlexTable stocksFlexTable;
    private HorizontalPanel addPanel;
    private VerticalPanel mainWindow;
    private TextBox newSymbolTextBox;
    private Button addButton;
    private Label lastUpdatedLabel;
    private ArrayList <String> stocks = new ArrayList<String>(); //Add this line



        public void onModuleLoad() {
        rootPanel = RootPanel.get();

        mainWindow = new VerticalPanel();
        rootPanel.add(mainWindow, 10, 10);
        mainWindow.setSize("267px", "175px");

        FlexTable stocksFlexTable = new FlexTable();

        //Add these lines
        stocksFlexTable.setText(0, 0, "Symbol");
        stocksFlexTable.setText(0, 1, "Price");
        stocksFlexTable.setText(0, 2, "Change");
        stocksFlexTable.setText(0, 3, "Remove");
        mainWindow.add(stocksFlexTable);

        addPanel = new HorizontalPanel();
        rootPanel.add(addPanel, 10, 200);
        addPanel.setSize("267px", "68px");

        newSymbolTextBox = new TextBox();
        newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() {
            public void onKeyPress(KeyPressEvent event) {
                if (event.getCharCode() == KeyCodes.KEY_ENTER){
                    addStock();
                }
            }
        });


        addPanel.add(newSymbolTextBox);
        newSymbolTextBox.setWidth("211px");

        addButton = new Button("Add");
        addButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                addStock();
            }
        });


        addPanel.add(addButton);

        lastUpdatedLabel = new Label("New Label");
        rootPanel.add(lastUpdatedLabel, 48, 274);



    }

    private void addStock() {
        final String symbol = newSymbolTextBox.getText().toUpperCase().trim();
        newSymbolTextBox.setFocus(true);

        // Stock code must be between 1 and 10 chars that are numbers, letters, or dots.
        if (!symbol.matches("^[0-9A-Z\\.]{1,10}$")) {
          Window.alert("'" + symbol + "' is not a valid symbol.");
          newSymbolTextBox.selectAll();
          return;
        }

        newSymbolTextBox.setText("");

     // don't add the stock if it's already in the watch list
        if (stocks.contains(symbol))
            return;

        // add the stock to the list
        int row = stocksFlexTable.getRowCount();
        stocks.add(symbol);
        stocksFlexTable.setText(row, 0, symbol);

        // add button to remove this stock from the list
        Button removeStock = new Button("x");
        removeStock.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {                 
            int removedIndex = stocks.indexOf(symbol);
            stocks.remove(removedIndex);
            stocksFlexTable.removeRow(removedIndex + 1);
        }
        });
        stocksFlexTable.setWidget(row, 3, removeStock);
    }
}

当我运行Web应用程序时,我无法添加库存。但是,该程序确实区分了坏的股票名称和可接受的股票名称。相反,我得到一个“未捕获的异常转义”错误,该程序并没有真正做任何事情。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

使用调试器并单步执行代码。在addStock的第一行设置一个断点,找到哪一行崩溃。一旦找到哪一行,你就可以检测线路,找出引起问题的方面 - 假设你不能通过查看该线来推断出问题。