calculateresultbean.java

来自「java EJB 编程源代码。」· Java 代码 · 共 84 行

JAVA
84
字号
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 + =
减小字号Ctrl + -
显示快捷键?