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

📄 numberfilter.java

📁 本系统是用 java 语言实现的一个 Email客户端
💻 JAVA
字号:
package net.suberic.util.gui.propedit;/** * A PropertyEditorListener which disallows non-integers, and can also be * used for min/max settings. */public class NumberFilter extends PropertyEditorAdapter implements ConfigurablePropertyEditorListener {  String originalValue;  boolean checkMin = false;  int min;  boolean checkMax = false;  int max;  /**   * Configures this filter from the given key.   */  public void configureListener(String key, String property, String propertyBase, String editorTemplate, PropertyEditorManager manager) {    originalValue = manager.getProperty(property, "");    String minProp = manager.getProperty(key + ".min", "");    if (minProp != "") {      try {        min = Integer.parseInt(minProp);        checkMin = true;      } catch (NumberFormatException nfe) {      }    }    String maxProp = manager.getProperty(key + ".max", "");    if (maxProp != "") {      try {        max = Integer.parseInt(maxProp);        checkMax = true;      } catch (NumberFormatException nfe) {      }    }  }  /**   * Called when a property is about to change.  If the value is not ok   * with the listener, a PropertyValueVetoException should be thrown.   *   * In this case, if the entry is either not a number, or is not within   * the min/max range, an error is thrown.   */  public void propertyChanging(PropertyEditorUI source, String property, String newValue) throws PropertyValueVetoException {    try {      if (newValue != null && newValue.length() > 0 && ! newValue.equals(originalValue)) {        int currentValue = Integer.parseInt(newValue);        if (checkMin) {          if (currentValue < min) {            throw new PropertyValueVetoException(property, newValue, "value must be at least " + min, this);          }        }        if (checkMax) {          if (currentValue > max) {            throw new PropertyValueVetoException(property, newValue, "value must be at most " + max, this);          }        }      }    } catch (NumberFormatException nfe) {      throw new PropertyValueVetoException(property, newValue, "entry must be a number.", this);    }  }}

⌨️ 快捷键说明

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