资源描述:
《JAVA模拟科学计算器.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassCaextendsJFrameimplementsActionListener{//***********************************************************************//标准型计算器控件键钮staticJFramef1=newJFrame("计算器");privateStringKEYS[]={"7","8","9","/","sq
2、rt","4","5","6","*","%","1","2","3","-","1/x","0","+/-",".","+","="};privateStringM[]={"","MC","MR","MS","M+"};privateStringCOM[]={"Backspace","CE","C"};privateJButtonkeys[]=newJButton[KEYS.length];privateJButtoncom[]=newJButton[COM.length];privateJButtonm[]=newJButto
3、n[M.length];privateJTextFieldresult,hh,jj;MenuBarmenubar1=newMenuBar();Menuedit=newMenu("编辑(E)"),view=newMenu("查看(V)"),help=newMenu("帮助(H)");MenuItemcopy=newMenuItem("复制(C)"),paste=newMenuItem("粘贴(P)"),standar=newMenuItem("标准型(T)"),science=newMenuItem("科学型(S)"),numgro
4、up=newMenuItem("数字分组(I)"),helpt=newMenuItem("帮助主题(H)"),about=newMenuItem("关于计算器(A)");privatebooleanfirstDigit=true;//判断第一个输入的字符是否是数字privatedoubleresultNum=0.0,resultNum2=0.0;//中间结果privateStringoperator="=",co,str,operator2="=";privatebooleanoperateValidFlag=true;//***
5、********************************************************************//科学性计算器控件及按钮staticJFramef2=newJFrame("科学计算器");privateJTextFieldresult2;privateString[]KON={"sta","F-E","(",")","MC","Ave","dms","Exp","In","MR","Sum","sin","x^y","log","MS","s","cos","x^3","n!","M+",
6、"Dat","tan","x^2","1/x","pi"};privateString[]KO={"7","8","9","/","Mod","And","4","5","6","*","Or","Xor","1","2","3","-","Lsh","Not","0","+/-",".","+","=","Int","A","B","C","D","E","F"};privateStringITM[]={"标准型","科学型","十六进制数(H)F5","十进制(D)F6","八进制(O)F7","二进制(B)F8","四字(Q
7、)F12","DWORD值(R)F2","单字(W)F3","字节(Y)F4","数字分组(I)"};privatefinalString[]COMM={"Backspace","CE","C"};privateJButtoncomm[]=newJButton[COMM.length];privateJButtonkon[]=newJButton[KON.length];privateJButtonko[]=newJButton[KO.length];privateMenuItemitm[]=newMenuItem[ITM.len
8、gth];privateJPanelpanel0,panel1,panel2,panel3,panel4,panel5,panel6;Checkboxcheckbox1,checkbox2,checkbox3,checkbox4;MenuBarme