资源简介

用java编写的简易计算器实验报告 实现计算器的加、减、乘、除等基本功能,参考Windows计算器增加多种功能,并处理异常。 private JTextArea text;//输入框 private JButton buttonBackspace,buttonCE,buttonC;//结果操作键 private JButton btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn0;//数字键 private JButton btnMC,btnMR,btnMS,btnMAdd,btnMSub;//存储操作键 private JButton btnPlus,btnMinus,btnDivide,btnMultiply,btnEqual;//加减乘除等号键 private JButton btnPercent,btnSqrt,btnNegtive,btnReciprocal,btnDot;//"%",开方,"+/-",倒数,小数点 …… MainFrame() { super("计算器"); setBounds(100,100,335,310); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.getContentPane().setLayout(new FlowLayout(FlowLayout.RIGHT)); panel=new JPanel(); panel2=new JPanel(); gridpanelM=new JPanel(); gridpanelR=new JPanel(); gridpanelN=new JPanel(); panel.setLayout(new BorderLayout(5,5));//水平垂直间距 panel2.setLayout(new BorderLayout(5,5)); gridpanelM.setLayout(new GridLayout(1,5,5,5)); gridpanelR.setLayout(new GridLayout(1,3,5,5)); gridpanelN.setLayout(new GridLayout(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; ……………… }

资源截图

代码片段和文件信息

评论

共有 条评论