{
displayField.setText("");
start=false;
if(input.equals("+/-"))
displayField.setText(displayField.getText()+"-");
}
if(!input.equals("+/-"))
{
String str=displayField.getText();
if(input.equals("退格"))//退格键的实现方法
{
if(str.length()0)
displayField.setText(str.substring(0,str.length()-1));
}
else if(input.equals("C"))//清零键的实现方法
{
displayField.setText("0");
start=true;
}
else
displayField.setText(displayField.getText()+input);
}
}
else if (e.getActionCommand()=="二进制")//二进制的转换
{
int n=Integer.parseInt(displayField.getText());
displayField.setText(Integer.toBinaryString(n));
}
else if (e.getActionCommand()=="八进制")//八进制的转换
{
int n=Integer.parseInt(displayField.getText());
displayField.setText(Integer.toOctalString(n));
}
else if (e.getActionCommand()=="退出")//选项中退出的处理方法
{
System.exit(0);
}
else if (e.getActionCommand()=="用法")//按下'帮助'菜单栏中用法的处理方法
{
label_dialog.setText("sqrt,exp等键是先输运算符再输数字\n");
dialog.setLocation(400,250);
dialog.setVisible(true);
}
else//各运算符的识别
{
String command=e.getActionCommand();
if(start)
{
lastCommand=command;
}
else
{
calculate(Double.parseDouble(displayField.getText()));
lastCommand=command;
start=true;
}
}
}
public void calculate(double x)//各运算符的具体运算方法
{
double d=0;
if (lastCommand.equals("+"))
result+= x;
else if (lastCommand.equals("-"))
result-=x;
else if (lastCommand.equals("*"))
result*=x;
else if (lastCommand.equals("/"))
result/=x;
else if (lastCommand.equals("="))
result=x;
else if (lastCommand.equals("sqrt"))
{
d=Math.sqrt(x);
result=d;
}
else if (lastCommand.equals("exp"))
{
d=Math.exp(x);
result=d;
}
else if (lastCommand.equals("log"))
{
d=Math.log(x);
result=d;
}
else if (lastCommand.equals("tan"))
{
d=Math.tan(x);
result=d;
}
else if (lastCommand.equals("cos"))
{
d=Math.cos(x);
result=d;
}
else if (lastCommand.equals("sin"))
{
d=Math.sin(x);
result=d;
}
displayField.setText(""+ result);
}
public void windowClosing(WindowEvent e)
{
if(e.getSource()==dialog)
dialog.setVisible(false);//隐藏对话框
else
System.exit(0);
}
public void windowOpened(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public static void main(String args[])
{
Calculator calculator=new Calculator();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)//单击窗口关闭按钮时触发并执行实现窗口监听器接口中的方法
{
System.exit(0);//结束程序运行
}
public void windowOpened(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
}
java arctanjava arctan是什么,让我们一起了解一下?
arctan是java中数学运算的三角函数方法,tan() 三角正切,通过编程Java代码实现,常用的还有cos() 三角余弦,sin()为 三角正弦,asin() 正弦的反函数,cos() 余弦的反函数,tan() 正切的反函数 。
推荐阅读
- erp信息系统的调研项目,erp系统应用调研报告
- gis棚格图片转为cad,gisshp转栅格
- python爬虫获取html,python爬虫获取图片
- 生产力升级flutter,生产力更新
- 十大编程语言go 十大编程语言有哪些
- 拼多多妙手手机版ios,拼多多妙手手机版app
- 三国即时战略游戏单机版,三国战略单机手机游戏
- 如何辨别电商假货和假货,电商防伪查询
- mysql查询方法怎么写 mysql查询语句大全及用法