用java编写的简易计算器实验报告实现计算器的加、减、乘、除等基本功能,参考Windows计算器增加多种功能,并处理异常。
privateJTextAreatext;//输入框privateJButtonbuttonBackspace,buttonCE,buttonC;//结果操作键privateJButtonbtn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn0;//数字键privateJButtonbtnMC,btnMR,btnMS,btnMAdd,btnMSub;//存储操作键privateJButtonbtnPlus,btnMinus,btnDivide,btnMultiply,btnEqual;//加减乘除等号键privateJButtonbtnPercent,btnSqrt,btnNegtive,btnReciprocal,btnDot;//"%",开方,"+/-",倒数,小数点……MainFrame(){super("计算器");setBounds(100,100,335,310);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.getContentPane().setLayout(newFlowLayout(FlowLayout.RIGHT));panel=newJPanel();panel2=newJPanel();gridpanelM=newJPanel();gridpanelR=newJPanel();gridpanelN=newJPanel();panel.setLayout(newBorderLayout(5,5));//水平垂直间距panel2.setLayout(newBorderLayout(5,5));gridpanelM.setLayout(newGridLayout(1,5,5,5));gridpanelR.setLayout(newGridLayout(1,3,5,5));gridpanelN.setLayout(newGridLayout(4,5,5,5));panel.add(gridpanelR,BorderLayout.NORTH);panel.add(panel2,BorderLayout.CENTER);panel2.add(gridpanelM,BorderLayout.NORTH);panel2.add(gridpanelN,BorderLayout.CENTER);this.getContentPane().add(text,BorderLayout.NORTH);this.getContentPane().add(panel,BorderLayout.SOUTH;………………}
1