十天学习GWT笔记 之 第二天(创建第一个应用程序:StockWatcher)

GWT2.0新特性之UiBinder GWT2.0中提供了一个UiBinder类,通过它我们可以使用XML语言对界面进行描述,这种操作叫作绑定。通过UiBinder,可以实现许多功能:HTML绑定、控件绑定、CSS绑定、事件管理、资源打包、创建控件等一、html绑定新建一个Google Web Application Project,然后在其client包内新建一个UiBinder,命名为HtmlBind,那么系统会自动的生 阅读详情

(I)创建第一个Web Application Project:StockWatcher(成功!)

 

打开eclipse(Helios),新建一个Web Application Project(直接点击工具栏里的图标),填上工程名(StockWatcher)和包名

(com.google.gwt.sample.stockwatcher),确认GWT2.1.0和App Engine-1.4.0已经被选中->finish。OK! StockWatcher创建成功!

 

(II)在hosted mode下测试StockWatcher(成功!)

 

选中StockWatcher直接在工具栏里点击运行按钮。在Console窗口中显示:

Initializing AppEngine server
Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
Successfully processed /home/explore/workspace/StockWatcher/war/WEB-INF/appengine-web.xml
Successfully processed /home/explore/workspace/StockWatcher/war/WEB-INF/web.xml
The server is running at http://localhost:8888/

在Develope Mode 窗口下显示:

http://127.0.0.1:8888/StockWatcher.html?gwt.codesvr=127.0.0.1:9997

把该网址copy到firefox地址栏里就可以查看该工程了!(注意:firefox在这里可能提示要安装一个叫GWT for firefox的插件,根据提示右击保存安装就好了!)

这样测试就完成了。

 

(III)编写StockWatcher的Java代码

一、打开StockWatcher->src->com.google.gwt.sample.stockwatcher.client->stockwatcher.java

输入java代码:(一共224行)

package com.google.gwt.sample.stockwatcher.client;

import java.util.ArrayList;
import java.util.Date;

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.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
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.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class StockWatcher implements EntryPoint {

    private static final int REFRESH_INTERVAL = 5000;
    private VerticalPanel mainPanel = new VerticalPanel();
    private FlexTable stocksFlexTable = new FlexTable();
    private HorizontalPanel addPanel = new HorizontalPanel();
    private TextBox newSymbolTextBox = new TextBox();
    private Button addStockButton = new Button("Add");
    private Label lastUpdatedLabel = new Label();
    private ArrayList<String> stocks = new ArrayList<String>();

    /**
     * Entry point method.
     */
    public void onModuleLoad() {
        // Create table for stock data.
        stocksFlexTable.setText(0, 0, "Symbol");
        stocksFlexTable.setText(0, 1, "Price");
        stocksFlexTable.setText(0, 2, "Change");
        stocksFlexTable.setText(0, 3, "Remove");
       
        // Add styles to elements in the stock list table.
        stocksFlexTable.setCellPadding(6);
        stocksFlexTable.getRowFormatter().addStyleName(0, "watchListHeader");
        stocksFlexTable.addStyleName("watchList");
        stocksFlexTable.getCellFormatter().addStyleName(0, 1, "watchListNumericColumn");
        stocksFlexTable.getCellFormatter().addStyleName(0, 2, "watchListNumericColumn");
        stocksFlexTable.getCellFormatter().addStyleName(0, 3, "watchListRemoveColumn");
       
        // Assemble Add Stock panel.
        addPanel.add(newSymbolTextBox);
        addPanel.add(addStockButton);
        addPanel.addStyleName("addPanel");

        // Assemble Main panel.
        mainPanel.add(stocksFlexTable);
        mainPanel.add(addPanel);
        mainPanel.add(lastUpdatedLabel);

        // Associate the Main panel with the HTML host page.
        RootPanel.get().add(mainPanel);

        // Move cursor focus to the input box.
        newSymbolTextBox.setFocus(true);

        // Setup timer to refresh list automatically.
        Timer refreshTimer = new Timer() {
            @Override
            public void run() {
                refreshWatchList();
            }
        };
        refreshTimer.scheduleRepeating(REFRESH_INTERVAL);

        // Listen for mouse events on the Add button.
        addStockButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                addStock();
            }

        });

        // Listen for keyboard events in the input box.
        newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() {
            public void onKeyPress(KeyPressEvent event) {
                if (event.getCharCode() == KeyCodes.KEY_ENTER) {
                    addStock();
                }
            }
        });

    }

    /**
     * Add stock to FlexTable. Executed when the user clicks the addStockButton
     * or presses enter in the newSymbolTextBox.
     */
    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 table.
        if (stocks.contains(symbol))
            return;

        // Add the stock to the table.
        int row = stocksFlexTable.getRowCount();
        stocks.add(symbol);
        stocksFlexTable.setText(row, 0, symbol);
        stocksFlexTable.setWidget(row, 2, new Label());
        stocksFlexTable.getCellFormatter().addStyleName(row, 1, "watchListNumericColumn");
        stocksFlexTable.getCellFormatter().addStyleName(row, 2, "watchListNumericColumn");
        stocksFlexTable.getCellFormatter().addStyleName(row, 3, "watchListRemoveColumn");

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

        // Get the stock price.
        refreshWatchList();

    }

    /**
     * Generate random stock prices.
     */

    private void refreshWatchList() {
        final double MAX_PRICE = 100.0; // $100.00
        final double MAX_PRICE_CHANGE = 0.02; // +/- 2%

        StockPrice[] prices = new StockPrice[stocks.size()];
        for (int i = 0; i < stocks.size(); i++) {
            double price = Random.nextDouble() * MAX_PRICE;
            double change = price * MAX_PRICE_CHANGE
                    * (Random.nextDouble() * 2.0 - 1.0);

            prices[i] = new StockPrice(stocks.get(i), price, change);
        }

        updateTable(prices);

    }

    /**
     * Update the Price and Change fields all the rows in the stock table.
     *
     * @param prices
     *            Stock data for all rows.
     */

    private void updateTable(StockPrice[] prices) {
        for (int i = 0; i < prices.length; i++) {
            updateTable(prices[i]);
        }
        // Display time_stamp showing last refresh.
        lastUpdatedLabel.setText("Last update : "
                + DateTimeFormat.getMediumDateTimeFormat().format(new Date()));

    }

    /**
     * Update a single row in the stock table.
     *
     * @param price
     *            Stock data for a single row.
     */
    private void updateTable(StockPrice price) {
        // Make sure the stock is still in the stock table.
        if (!stocks.contains(price.getSymbol())) {
            return;
        }

        int row = stocks.indexOf(price.getSymbol()) + 1;

        // Format the data in the Price and Change fields.
        String priceText = NumberFormat.getFormat("#,##0.00").format(
                price.getPrice());
        NumberFormat changeFormat = NumberFormat
                .getFormat("+#,##0.00;-#,##0.00");
        String changeText = changeFormat.format(price.getChange());
        String changePercentText = changeFormat
                .format(price.getChangePercent());

        // Populate the Price and Change fields with new data.
        stocksFlexTable.setText(row, 1, priceText);
        Label changeWidget = (Label)stocksFlexTable.getWidget(row, 2);
        changeWidget.setText(changeText + " (" + changePercentText + "%)");
       
        // Change the color of text in the Change field based on its value.
        String changeStyleName = "noChange";
        if (price.getChangePercent() < -0.1f) {
          changeStyleName = "negativeChange";
        }
        else if (price.getChangePercent() > 0.1f) {
          changeStyleName = "positiveChange";
        }

        changeWidget.setStyleName(changeStyleName);
    }
}

 

二、创建一个StockPrice.java并输入代码:

package com.google.gwt.sample.stockwatcher.client;

public class StockPrice {
    private String symbol;
    private double price;
    private double change;

    public StockPrice() {
    }

    public StockPrice(String symbol, double price, double change) {
        this.symbol = symbol;
        this.price = price;
        this.change = change;
    }

    public String getSymbol() {
        return this.symbol;
    }

    public double getPrice() {
        return this.price;
    }

    public double getChange() {
        return this.change;
    }

    public double getChangePercent() {
        return 100.0 * this.change / this.price;
    }

    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public void setChange(double change) {
        this.change = change;
    }

}

 


(III)补全完代码后继续在托管模式下测试(成功!)

 

 

 

 

(IV)将StockWatcher编译为JavaScript代码,并用firefox打开(成功!)

直接点击eclipse工具栏里的GWT编译按钮,在Console窗口中显示

Compiling module com.google.gwt.sample.stockwatcher.StockWatcher
   Compiling 6 permutations
      Compiling permutation 0...
      Compiling permutation 1...
      Compiling permutation 2...
      Compiling permutation 3...
      Compiling permutation 4...
      Compiling permutation 5...
   Compile of permutations succeeded
Linking into /home/explore/workspace/StockWatcher/war/stockwatcher
   Link succeeded
   Compilation succeeded -- 41.601s

表示已经编译成功,下面可以直接在eclipse中打开StockWatcher.html了。

StockWatcher->war->StockWatcher.html 右击选择open with->Web Browser, OK!

基于NXP BFU730F的宽带WiFi LNA设计:从原理到实测的完整指南 低噪声放大器(LNA)是无线通信接收链路中的关键器件,其性能直接决定了系统的接收灵敏度。LNA的核心原理是在放大微弱信号的同时,尽可能降低自身引入的噪声,并保持良好的线性度以应对强干扰。在宽带应用场景下,如覆盖2.4GHz至5.9GHz的现代WiFi系统,设计需在宽带匹配、噪声优化和增益平坦度之间取得精妙平衡。本文以NXP的BFU730F SiGe:C HBT晶体管为核心,深入解析一种采用电阻反馈和LC匹配网络的经典宽带LNA架构。该设计通过优化反馈网络,在宽达3.5GHz的频带内实现了优异的噪声系数(低至 阅读详情

相关推荐

利用腾讯云轻量服务器快速搭建网站CDN

腾讯云的轻量最近在主机和站长中间可谓是占尽来风头,优秀的线路,低廉的价格使得越来越多的人开始使用腾讯云的轻量级服务器来部署应用。由于腾讯云轻量服务器的海外服务器电信走的是CN2GIA线路带宽30m挺适合做CDN的,我就记录一下如何利用腾讯云香港的轻量服务器搭建一个CDN。 购买服务器 首先选购服务器,最近腾讯云在做活动,力度很大国内备案用户可以选用国内的服务器最低128元/年,未备案的可以选用香港或者新加坡的服务器。 购买链接 服务器系统选Debian、Ubuntu、centos都可以 一键脚

demo_top的博客 2530

python:「股价瞭望者」(StockWatcher

监测一只股票,低于或者高于某价格,就会给你的邮箱发邮件提醒你。

养乐多的博客 4629

stockwatcher:用于监控一只或多只股票的 CLI 应用程序

股票行情 一个简单的 CLI 应用程序,用于观察一组给定股票的活动。 构建和安装 $ make install 用法 $ stockwatcher --help Usage of stockwatcher: -i=1: Interval for stock data to be updated in seconds -s= " " : Symbols for ticker, comma seperate (no spaces) 例子 显示为符号、当前价格、先前价格和向上/向下指示器。 $ stockwatcher -s GOOG,IBM,YHOO,CSCO,AAPL,FB,TWTR -i 1

从数据到决策:用OpenClaw构建你的全自动AI投研工作流 —整合akshare-data、Stock-Watcher、Tavily Search与Self-Improving,打造安全、闭环智能体

本文将手把手教你,如何利用 OpenClaw 这一现象级开源工具,整合四大核心组件——akshare-data(本地A股数据源)、Stock-Watcher(自选股监控器)、Tavily Search(实时情报官)和 Self-Improving(策略进化引擎),构建一个安全、闭环、全自动的AI投研工作流。从此,你将拥有一个7x24小时在线、永不疲倦、持续进化的私人投资智囊团。

yangzhihua的专栏 1289

让AI自己炒股!基于OpenClaw Agentic Workflow的A股智能体搭建指南——AKShare、Tavily Search、Stock-Watcher、Self-Improving

本文介绍了如何利用OpenClaw框架构建一个完整的AI投资智能体系统,实现从数据采集到自主分析的闭环工作流。系统整合了四大核心模块:本地金融数据源(akshare-data)、实时情报监控(Tavily Search)、自选股跟踪(Stock-Watcher)和策略自进化(Self-Improving)。通过自然语言交互,该智能体可完成市场扫描、机会挖掘、风险评估等完整投研流程,成为7x24小时工作的"数字投资经理。

yangzhihua的专栏 1075

【译】GWT入门:设计应用

【译自:https://developers.google.com/web-toolkit/doc/latest/tutorial/design?hl=zh-CN】   致此,我们已经完成了所有的准备工作。   这一节,我们需要审视一下功能需求和用户界面。   一、检查功能需求   我们希望StockWatcher应用能完成: 可能添加股票 (提供简单的判断一个输入是否合法或已...

刘刚的空间 178

gwt新窗口打开url设置

gwt项目中,需要在新窗口打开url时,最简单的就是使用window对象的open方法。在项目开发中,遇到这样一个问题,以新窗口打开的页面缺少菜单、地址栏、工具栏等,简单的说法就是模态窗口。由于一直是在firefox中进行测试,导致这个问题没有被察觉,firefox是将新窗口在新标签中打开,因此不存在模态的情况,但是在ie下此问题就浮出水面了。原始代码是类似这个样子的:Win

LE5YO 3682

java 打开新页签_java – GWT打开页面在一个新的选项卡

我正在开发GWT应用程序,我使用com.google.gwt.user.client.Window.open(pageUrl, "_blank", "");打开新页面。并且在调用时打开一个新的选项卡,例如,直接按下按钮。但是我决定在打开新页面之前对服务器进行一些验证,并将调用放在上述方法之上public void onSuccess(Object response) {}它开始在新窗口中打开页面,...

weixin_39612122的博客 376

使用GWT第一个程序

今天头一次接触GWT写了一个welcome页面,感觉GWT不是特别难。只不过缺点是没有中文的API  (我也不懂英文,,肿么办?  google翻译呗。。)  还有刚刚编译的时候死慢。。 不过修改代码后直接刷新页面后就可以看到新的效果了。对于这点洒家还是比较满意的。至少不用每次都经过漫长的编译过程。。  好了不多说废话了。下面就开始我们的GWT之旅。 第一步 1、eclipse 我

T` 6642

GWT—《 文件导出、下载》

已经3年没接触smartgwt这么技术了 变化还是挺大的,以前很少写博客,用到的很多实用东西时间一长都忘记了,所以,尽量抽时间写写博客,和大家一起探讨学习。。。 很多项目基本都会有文件导出、下载的功能,那么GWT也不例外,少废话,入正题: 1,Window方式 Window.open(newURL, "_blank", null); 就是null参数控制新窗口为模态的,

在IT技术的世界,天天向上↑ 1116

GWT通过JSNI打印Web页面内容

GWT中通过JSNI调用JS脚本去执行web页面打印: 首先是预览打印界面,代码如下: [code="java"] package net.carefx.sde.editor.web.editor.client.partogram; import net.carefx.component.editor.web.client.jsni.PartogramScript; impor...

panzer_416的博客 336

Gwt 教程之实现客户端功能

  实现客户端功能 我们的StockWatcher 例子到目前为止已经很好了,回顾一下,我们用GWT 的widgets和 panels 已经设计并实现了UI ,并且为用户实现了键盘单击事件 的初始化。现在,我们要为应用程序写客户端代码,让它实现功能。 验证用户输入 当用户第一次使用StockWatcher ,他需要通过在文本框里输入存货订单标...

shiren1118的专栏 646

gwt如何运用定时器设置间断时间

scheduleRepeating 如: timer.scheduleRepeating( 1000 );其中timer为定时器组件对象

studyjavalm1017的专栏 360

gwt 线程控制

package com.dr.b2b.clien.ui.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 c...

zzy7182的专栏 208

数字格式化输出NumberFormat

————————————————————— java.text.NumberFormat类有三个方法可以产生下列数据的标准格式化器: 数字 货币 百分数 ————————————————————— 创建格式化器(默认地区Local格式): NumberFormat.getNumberInstance(); NumberFormat.getCurrencyInstance(); NumberForma

愿世界和平 1939

【译】GWT入门:创建一个GWT Project

【译自:https://developers.google.com/web-toolkit/doc/latest/tutorial/create?hl=zh-CN】   前两篇里 【译】GWT入门:设置Eclipse 和 【译】GWT入门:准备环境 分别介绍了如何在命令行下和eclipse里创建和启动一个GWT 的demo project,因此这里就略过这部分,将具体介绍一下生成的文件和包。 ...

刘刚的空间 310

GWT中日期的格式化

import com.google.gwt.i18n.client.DateTimeFormat;上面一行很重要,不能导错包...  Date date = new Date();//也可以是从前台获取的 DateTimeFormat formate = DateTimeFormat.getFormat("yyyy-MM-dd")String dates = formate.for

天行健,君子以自强不息!~ 2692

GWT笔记(5)

GWT笔记(5)Internationalization 国际化 (I18N)国际化(简写为i18n)是一个附加框架的过程,它让你的应用程序支持不同国家的语言。Localization 本地化(L10N)本地化(简写为l10n)为当使用框架定制应用程序的每一种语言时。GWT提供了完整的和可伸缩的国际化支持工具。还有拼写检查和语法错误检查等。实现国际化的标准Java方法是通过资源绑定和配置文

chszs的专栏 3409

GetNumberFormat详解

在网上看到,关于这个函数的资料极少,所以做个说明 int GetNumberFormat( LCID Locale, // 语言 DWORD dwFlags, // 如果lpFormat不为NULL,则dwFlags必须为0 LPCTSTR lpValue, // 输入的数字字符串 CONST N

baidu_25539425的博客 1622

Firefox 火狐浏览器国际版:全平台开源浏览器的坚守与进化

本文系统介绍火狐浏览器(Mozilla Firefox)的历史沿革、核心特性、技术架构及其在当代浏览器竞争中的独特价值。文章从火狐的诞生与版本迭代讲起,重点剖析其隐私保护、开源社区、扩展生态和适用平台等核心优势,并通过与 Chrome、Edge 的对比表格直观呈现差异。此外,还介绍了火狐的多进程架构、Gecko 渲染引擎与 WebRender 等性能亮点,最后探讨了火狐在隐私优先理念下的独特意义与所面临的市场挑战。

weixin_45787934的博客 237

CorelDRAW-X4-SP2精简增强版

在当今的设计领域中,CorelDRAWX4SP2精简版成为了一款广受欢迎的矢量图形设计软件。它不仅拥有强大的功能,还以简化的版本帮助用户更高效地完成设计任务。小编将详细介绍该版本的特点、使用技巧以及如何进行高效的图形设计。1.CorelDRAWX4SP2精简版CorelDRAWX4SP2精简版是CorelDRAW系列中的一个重要版本,针对用户的需求进行了功能精简,去除了冗余的部分,使得软件运行更加流畅。该版本尤其适合初学者和需要高效完成基本设计工作的用户。2.安装与界面介绍安装CorelDRAWX4SP2精简版相对简单,用户只需下载软件包,按照提示进行安装即可。安装完成后,启动软件,用户可以看到简洁的界面布局,主要包括工具栏、属性栏以及工作区。工具栏上集成了常用的绘图工具,如矩形、椭圆、铅笔等,方便用户快速找到所需工具。3.常用功能与快捷键在CorelDRAWX4SP2精简版中,有几个常用功能和快捷键非常实用,让用户能高效完成设计任务。导入与导出文件:使用Ctrl+I快捷键可以快速导入素材,用户只需在弹出的窗口中找到所需的文件进行导入。而导出文件可以直接通过“文件

上一篇: 十天学习GWT笔记 之 第一天(了解GWT并配置环境)
下一篇: ubuntu-10.10一个BUG的解决
deep_explore
博客等级 码龄16年 54粉丝 97原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值