⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numberformatexamplecontroller.java

📁 google web tookit,google web tookit,google web tookit ,google web tookit
💻 JAVA
字号:
/* * Copyright 2007 Google Inc. *  * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at *  * http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.google.gwt.sample.i18n.client;import com.google.gwt.i18n.client.NumberFormat;import com.google.gwt.user.client.ui.HasText;/** * Demonstrates how to use {@link NumberFormat}. */public class NumberFormatExampleController extends    AbstractFormatExampleController {  private static final String DEFAULT_INPUT = "31415926535.897932";  private NumberFormat activeFormat;  private final NumberFormatExampleConstants constants;  public NumberFormatExampleController(      final NumberFormatExampleConstants constants) {    super(DEFAULT_INPUT, constants.numberFormatPatterns());    this.constants = constants;  }  public NumberFormatExampleConstants getConstants() {    return constants;  }  @Override  protected String doGetPattern(String patternKey) {    if ("currency".equals(patternKey)) {      return NumberFormat.getCurrencyFormat().getPattern();    }    if ("decimal".equals(patternKey)) {      return NumberFormat.getDecimalFormat().getPattern();    }    if ("scientific".equals(patternKey)) {      return NumberFormat.getScientificFormat().getPattern();    }    if ("percent".equals(patternKey)) {      return NumberFormat.getPercentFormat().getPattern();    }    throw new IllegalArgumentException("Unknown pattern key '" + patternKey        + "'");  }  @Override  protected void doParseAndRememberPattern(String pattern) {    activeFormat = NumberFormat.getFormat(pattern);  }  @Override  protected void doParseInput(String toParse, HasText output, HasText error) {    if (!"".equals(toParse)) {      try {        double x = Double.parseDouble(toParse);        String s = activeFormat.format(x);        output.setText(s);      } catch (NumberFormatException e) {        String errMsg = constants.failedToParseInput();        error.setText(errMsg);      }    } else {      output.setText("<None>");    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -