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

📄 calculateresultbean.java

📁 j2ee ejb编程实例.j2ee ejb编程实例.
💻 JAVA
字号:
package calculatebean;

import java.awt.*;
import javax.swing.JLabel;

/**
 *  这个Bean是用来处理计算的,并且返回计算结果
 */

public class CalculateResultBean
    extends JLabel {
  BorderLayout borderLayout1 = new BorderLayout();
  private String calculateValue;

  public CalculateResultBean() {
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    this.setLayout(borderLayout1);
  }

  public void setCalculateValue(String calculateValue, int X_value, int Y_value) {
    /* 计算设置器的实现 */

    int caresult1 = 0;
    double caresult2 = 0;
    String CaResult = null;

    if (calculateValue.equals("+")) {
      CaResult = Integer.toString(X_value);
      CaResult = CaResult + " + " + Integer.toString(Y_value);
      caresult1 = X_value + Y_value; // 做加法运算
      CaResult = CaResult + " = " + Integer.toString(caresult1);
    }
    if (calculateValue.equals("-")) {
      CaResult = Integer.toString(X_value);
      CaResult = CaResult + " - " + Integer.toString(Y_value);
      caresult1 = X_value - Y_value; // 做减法运算
      CaResult = CaResult + " = " + Integer.toString(caresult1);
    }
    if (calculateValue.equals("*")) {
      CaResult = Integer.toString(X_value);
      CaResult = CaResult + " * " + Integer.toString(Y_value);
      caresult1 = X_value * Y_value; // 做乘法运算
      CaResult = CaResult + " = " + Integer.toString(caresult1);
    }
    if (calculateValue.equals("/")) {
      if (Y_value == 0) {
        // 如果除数为0
        CaResult = Integer.toString(X_value);
        CaResult = CaResult + " / " + Integer.toString(Y_value);
        CaResult = CaResult + " = ∞";
      }
      else {
        // 如果除数不为0
        CaResult = Integer.toString(X_value);
        CaResult = CaResult + " / " + Integer.toString(Y_value);
        caresult2 = (double) X_value / Y_value; // 做除法运算
        CaResult = CaResult + " = " + Double.toString(caresult2);
      }
    }
    this.calculateValue = CaResult;
  }

  public String getCalculateValue() {
    /* 计算获取器的实现 */
    return calculateValue;
  }
}

⌨️ 快捷键说明

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