/**
* 计算器的核心逻辑实现
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
float num1 = Float.parseFloat(this.jTextField1.getText());
float num2 = Float.parseFloat(this.jTextField2.getText());
int flag = jComboBox1.getSelectedIndex();
float result = 0.0f;
switch (flag) {
case 0:
result = num1 + num2;
this.jTextField3.setText(Float.toString(result));
break;
case 1:
result = num1 - num2;
this.jTextField3.setText(Float.toString(result));
break;
case 2:
result = num1 * num2;
this.jTextField3.setText(Float.toString(result));
break;
case 3:
result = num1 / num2;
this.jTextField3.setText(Float.toString(result));
break;
}
}
阅读(1383) | 评论(0) | 转发(0) |