科学计算器程序Java代码
实用文档 功能举例: 源程序如下: importimport java.awt.BorderLayout; importimport java.awt.Color; importimport java.awt.Dimension; importimport java.awt.Font; importimport java.awt.GridLayout; importimport java.awt.event.ActionEvent; importimport java.awt.event.ActionListener; importimport java.text.Decimalat; importimport javax.swing.BorderFactory; importimport javax.swing.ButtonGroup; importimport javax.swing.JButton; importimport javax.swing.JCheckBoxMenuItem; importimport javax.swing.JFrame; importimport javax.swing.JMenu; importimport javax.swing.JMenuBar; importimport javax.swing.JMenuItem; importimport javax.swing.JPanel; importimport javax.swing.JRadioButtonMenuItem; importimport javax.swing.JTextField; publicpublic classclass Calucator extendsextends JFrame { privateprivate JTextField tf; privateprivate JPanel panel1, panel2, panel3, panel4; 文案大全 实用文档 privateprivate JMenuBar myBar; privateprivate JMenu menu1, menu2, menu3; privateprivate JMenuItem editItem1, editItem2, help1, help2, help3; privateprivate JRadioButtonMenuItem seeItem1, seeItem2;//单选框 privateprivate JCheckBoxMenuItem seeItem3;//复选框 privateprivate ButtonGroup bgb; privateprivate String back; privateprivate booleanboolean IfResult = truetrue, flag = falsefalse; privateprivate String oper = “=“; privateprivate doubledouble result = 0; privateprivate Num numActionListener; privateprivate Decimalat df; publicpublic Calucator(){ supersuper(“科学计算器“);//设置标题栏 df = newnew Decimalat(“#.####“);//保留四位小数 thisthis.setLayout(newnew BorderLayout(10, 5)); panel1 = newnew JPanel(newnew GridLayout(1, 3, 10, 10)); panel2 = newnew JPanel(newnew GridLayout(5, 6, 5, 5));//5行6列 panel3 = newnew JPanel(newnew GridLayout(5, 1, 5, 5)); panel4 = newnew JPanel(newnew BorderLayout(5, 5)); /** * 菜单栏 */ myBar = newnew JMenuBar(); menu1 = newnew JMenu(“编辑(E)“); menu2 = newnew JMenu(“查看(V)“); menu3 = newnew JMenu(“帮助(H)“); menu1.setFont(newnew Font(“宋体“, Font.PLAIN, 12)); menu2.setFont(newnew Font(“宋体“, Font.PLAIN, 12)); menu3.setFont(newnew Font(“宋体“, Font.PLAIN, 12)); /** * 编辑栏 */ editItem1 = newnew JMenuItem(“复制(C) Ctrl+C“); editItem2 = newnew JMenuItem(“粘贴(P) Ctrl+V“); editItem1.setFont(newnew Font(“宋体“,Font.PLAIN,12)); editItem2.setFont(newnew Font(“宋体“,Font.PLAIN,12)); 文案大全 实用文档 /** * 查看栏 */ seeItem1 = newnew JRadioButtonMenuItem(“科学型(T)“); seeItem2 = newnew JRadioButtonMenuItem(“标准型(S)“); seeItem3 = newnew JCheckBoxMenuItem(“数字分组(I)“); seeItem1.setFont(newnew Font(“宋体“,Font.PLAIN,12)); seeItem2.setFont(newnew Font(“宋体“,Font.PLAIN,12)); seeItem3.setFont(newnew Font(“宋体“,Font.PLAIN,12)); /** * 帮助栏 */ help1 = newnew JMenuItem(“帮助主题(H)“); help2 = newnew JMenuItem(“关于计算器(A)“); help1.setFont(newnew Font(“宋体“,Font.PLAIN,12)); help2.setFont(newnew Font(“宋体“,Font.PLAIN,12)); bgb = newnew ButtonGroup();//选项组 menu1.add(editItem1); menu1.add(editItem2); menu2.add(seeItem1); menu2.add(seeItem2); menu2.addSeparator();//添加一条分割线 menu2.add(seeItem3); menu3.add(help1); menu3.addSeparator();//添加一条分割线 menu3.add(help2); myBa