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

📄 numberrangeexception.java~2~

📁 java2参考大全上的例子的源码和自己的理解.
💻 JAVA~2~
字号:
package numberrangeexception;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class NumberRangeException
    extends Exception {
  String answerStr;
  public NumberRangeException(String msg) {
    super(msg);
  }

  public boolean action(Event evt, Object arg) {
    try {
      int answer = CalcAnswer();
      answerStr = String.valueOf(answer);
    }
    catch (NumberRangeException e) {
      answerStr = e.getMessage();
    }
    repaint();
    return true;
  }

  public int CalcAnswer() throws NumberRangeException {
    int int1, int2;
    int answer = -1;

    String str1 = textField1.getText();
    String str2 = textField2.getText();
    try {
      int1 = Integer.parseInt(str1);
      int2 = Integer.parseInt(str2);
      if ( (int1 < 10) || (int1 > 20) ||
          (int2 < 10) || (int2 > 20)) {
        NumberRangeException e =
            new NumberRangeException
            ("Numbers not within the specified range.");
        throw e;

      }
      answer = int1 + int2;
    }
    catch (NumberFormatException e) {
      answerStr = e.toString();
    }
    return answer;
  }
}

⌨️ 快捷键说明

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