double dtemp = Double.parseDouble(temp1);
String temp2 = memory.toString();
dtemp += Double.parseDouble(temp2);
temp1 = String.valueOf(dtemp);
memory.replace(0, memory.length(), temp1);
}
else if(s.equals("1/x"))
{
//如果按键为1/x则将文本框中的数据为它的倒数
String temp = tResult.getText().trim();
double dtemp = Double.parseDouble(temp);
tResult.setText(""+1/dtemp);
}
else if(s.equals("sqrt"))
{
//如果按键为sqrt则将文本框中的内容求平方根
String temp = tResult.getText().trim();
double dtemp = Double.parseDouble(temp);
tResult.setText(""+Math.sqrt(dtemp));
}
else if(s.equals("+"))
{
str.setLength(0);
if(currentOp==0)
{
preOp = currentOp = 1;
op2 = 0;
tResult.setText(""+op1);
}
else
{
currentOp = preOp;
preOp = 1;
switch(currentOp){
case 1:
op1 += op2;
tResult.setText(""+op1);
break;
case 2:
op1 -= op2;
tResult.setText(""+op1);
break;
case 3:
op1 *= op2;
tResult.setText(""+op1);
break;
case 4:
op1 /= op2;
tResult.setText(""+op1);
break;
}
}
}
else if(s.equals("-")){
str.setLength(0);
if(currentOp==0)
{
preOp=currentOp=2;//op1=op2;op2=0;
tResult.setText(""+op1);
}
else
{
currentOp =preOp;
preOp =2;
switch(currentOp){
case 1:op1=op1+op2;tResult.setText(""+op1);break;
case 2:op1=op1-op2;tResult.setText(""+op1);break;
case 3:op1=op1*op2;tResult.setText(""+op1);break;
case 4:op1=op1/op2;tResult.setText(""+op1);break;
}
}
}
else if(s.equals("*"))//*
{
str.setLength(0);
if(currentOp==0)
{
preOp=currentOp=3;//op1=op2;op2=1;
tResult.setText(""+op1);//op1=op2;
}
else
{
currentOp =preOp;
preOp =3;
switch(currentOp){
case 1:op1=op1+op2;tResult.setText(""+op1);break;
case 2:op1=op1-op2;tResult.setText(""+op1);break;
case 3:op1=op1*op2;tResult.setText(""+op1);break;
case 4:op1=op1/op2;tResult.setText(""+op1);break;
}
}
}
else if(s.equals("/"))// /
{
str.setLength(0);
if(currentOp==0)
{
preOp=currentOp=4;//op2=1;
tResult.setText(""+op1);//op1=op2;
}
else
{
currentOp =preOp;
preOp =4;
switch(currentOp){
case 1:op1=op1+op2;tResult.setText(""+op1);break;
case 2:op1=op1-op2;tResult.setText(""+op1);break;
case 3:op1=op1*op2;tResult.setText(""+op1);break;
case 4:op1=op1/op2;tResult.setText(""+op1);break;
}
}
}
else if(s.equals("="))// =
{
if(currentOp==0)
{
str.setLength(0);
tResult.setText(""+op2);
}
else
{
str.setLength(0);
currentOp =preOp;
switch(currentOp){
case 1:op1=op1+op2;tResult.setText(""+op1);break;
case 2:op1=op1-op2;tResult.setText(""+op1);break;
case 3:op1=op1*op2;tResult.setText("qu
急求?。。∪绾斡胘ava程序代码实现计算器界面package jisuanqi_new;
import java.awt.*;
import java.awt.event.*;
public class JiSuanQi_new implements ActionListener
{
Panel p1;//声明面板p1
TextField t1;//声明文本行t1
String[] label = {"7","8","9","/","4","5","6","*","1","2","3","-","0",".","=","+"};//声明标签数组label1存放按钮上的标签
Button[] b;//声明按钮数组存放16个按钮
private int i;//声明i以备后用
private String op1 = "0";//运算数备用
private String operator = "+";//运算符备用
private boolean append = false;//备用
public JiSuanQi_new()//构造方法
{
t1=new TextField();//初始化文本行t1
推荐阅读
- flutter控件覆盖,flutter嵌套
- 小米k50怎么降级鸿蒙系统的简单介绍
- 新生电商如何发展,电商如何快速发展
- 江苏专业网站搭建费用低,专业建设网站的公司
- linux性能指标命令 linux常用性能命令
- ChatGPT免费破解最新版,chatcraft pro 破解版
- 包含代理软件的词条
- 公众号文章最后的阅读量,公众号文章最后的阅读量怎么算
- php数据传递js php传数据给ajax的实例