java计算器源代码 .docx
精品名师归纳总结java 运算器源代码 仿 win7import java.awt.* 。import javax.swing.* 。import java.awt.event.*。class Cal extends JFrame implements ActionListener,MouseListenerJMenuBar menubar 。JMenu menu_check,menu_edit,menu_help。JMenuItem menuitem_science,menuitem_check,menuitem_exit,menuitem_copy,menuitem_paste,menuitem1_copy,menuitem1_paste,menuitem_chelp,menuitem_about。JCheckBoxMenuItem menuitem_standard 。JTextField ta1。int x,result2 。double op1,op2,opall 。private boolean end=false,flag=false,add=false,sub=false,cheng=false,chu=false,flagop2=false。JButton b_mc,b_mr,b_ms,b_mjia,b_mjian,b_tui,b_ce,b_c,b_jj, b_dui,b_7,b_8,b_9,b_chu,b_baifenhao,b_4,b_5,b_6,b_cheng, b_daoshu,b_1,b_2,b_3,b_jian,b_0,b_dian,b_jia,b_dengyu。JPanel p_all,p_button1,p_button2,p_txt,p1,p2,p3,p4,p5。private String str,resultstr 。JPopupMenu popupmenu 。Container con=this.getContentPane 。Font font=new Font" 微软雅黑 ",Font.PLAIN,12。Color color=new Color120,220,120 。可编辑资料 - - - 欢迎下载精品名师归纳总结CalString ssupers。setSize220,315。setResizablefalse。setVisibletrue 。Dimension scr=Toolkit.getDefaultToolkit.getScreenSize 。Dimension frm=this.getSize 。setLocationscr.width-frm.width/2,scr.height-frm.height/2。Toolkit tk=Toolkit.getDefaultToolkit。/ 程序默认图标设置setIconImagetk.createImage"D:sd.jpg"。setDefaultCloseOperationJFrame.EXIT_ON_CLOSE。/-制作框架结构 -/-菜单栏 -menubar=new JMenuBar 。menubar.setPreferredSizenew Dimensionfrm.width,19。menu_check=new JMenu" 查看 V"。menu_check.setFontfont 。menu_check.setForegroundColor.black 。menuitem_standard=new JCheckBoxMenuItem"标准型 ",true 。menuitem_standard.setFontfont。menuitem_standard.setForegroundColor.black。menuitem_science=new JMenuItem"科学型 "。menuitem_science.setFontfont 。可编辑资料 - - - 欢迎下载精品名师归纳总结menuitem_science.setForegroundColor.black 。menuitem_check=new JMenuItem"查看分组 "。menuitem_check.setFontfont 。menuitem_check.setForegroundColor.black。menuitem_exit=new JMenuItem"退出"。menuitem_exit.setFontfont。menuitem_exit.setForegroundColor.black。menuitem_exit.addActionListenerthis。menu_check.addmenuitem_standard。menu_check.addmenuitem_science 。menu_check.addSeparator 。menu_check.addmenuitem_check 。menu_check.addSeparator 。menu_check.addmenuitem_exit 。menubar.addmenu_check 。menu_edit=new JMenu" 编辑 E"。menu_edit.setFontfont 。menu_edit.setForegroundColor.black 。menu_edit.setMnemonicKeyEvent.VK_E 。menuitem_copy=new JMenuItem"复制 C "。menuitem_copy.setFontfont。menuitem_copy.setForegroundColor.black 。menuitem_copy.setAcceleratorKeyStroke.getKeyStrokeKeyEvent.VK_C,InputEvent.CTRL_MASK。menuitem_copy.addActionListenerthis。menuitem_paste=new JMenuItem"粘贴 P "。menuitem_paste.setFontfont。menuitem_paste.setForegroundColor.black。menuitem_paste.setAcceleratorKeyStroke.getKeyStrokeKeyEvent.VK_V,InputEvent.CTRL_MASK 。可编辑资料 - - - 欢迎下载精品名师归纳总结menuitem_paste.addActionListenerthis。menu_edit.addmenuitem_copy。menu_edit.addmenuitem_paste。menubar.addmenu_edit 。menu_help=new JMenu" 帮忙 H"。menu_help.setFontfont 。menu_help.setForegroundColor.black 。menuitem_chelp=new JMenuItem"查看帮忙 "。menuitem_chelp.setFontfont。menuitem_chelp.setForegroundColor.black。menuitem_about=new JMenuItem"关于运算器 "。menuitem_about.setFontfont。menuitem_about.setForegroundColor.black。menuitem_about.addActionListenerthis。menu_help.addmenuitem_chelp。menu_help.addSeparator 。menu_help.addmenuitem_about。menubar.addmenu_help 。setJMenuBarmenubar 。/-文本框 -ta1=new JTextField"0" 。ta1.setFontnew Font" 微软雅黑 ",Font.PLAIN,13。ta1.setEditablefalse 。/ta1.setOpaquefalse 。ta1.setHorizontalAlignmentJTextField.RIGHT 。可编辑资料 - - - 欢迎下载精品名师归纳总结ta1.setPreferredSizenew Dimensionfrm.width-26,45。ta1.addMouseListenerthis 。p_all=new JPanel。p_all.setPreferredSizenew Dimensionfrm.width-6,250。/p_all.setBackgroundcolor 。p_all.setLayoutnew FlowLayoutFlowLayout.CENTER,0,3 。p_txt=new JPanel 。p_txt.setPreferredSizenew Dimensionfrm.width-6,53。p_txt.setLayoutnew FlowLayoutFlowLayout.CENTER,0,7 。p_txt.addta1 。p_all.addp_txt 。con.addp_all,BorderLayout.CENTER。/-按钮区 -p_button1=new JPanel 。p_button1.setPreferredSizenew Dimensionfrm.width-25,131。p_button1.setLayoutnew FlowLayoutFlowLayout.LEFT,0,3 。p_all.addp_button1 。p1=new JPanel。p1.setPreferredSizenew Dimensionfrm.width-25,127。p1.setLayoutnew GridLayout4,5,5,6 。b_mc=new JButton"MC" 。可编辑资料 - - - 欢迎下载精品名师归纳总结b_mc.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_mc.setMarginnew Insets0,0,0,0 。b_mc.setForegroundColor.blue 。b_mc.addActionListenerthis 。b_mr=new JButton"MR" 。b_mr.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_mr.setMarginnew Insets0,0,0,0 。b_mr.setForegroundColor.blue 。b_mr.addActionListenerthis 。b_ms=new JButton"MS" 。b_ms.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_ms.setMarginnew Insets0,0,0,0 。b_ms.setForegroundColor.blue 。b_ms.addActionListenerthis 。b_mjia=new JButton"M+"。b_mjia.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_mjia.setMarginnew Insets0,0,0,0 。b_mjia.setForegroundColor.blue 。b_mjia.addActionListenerthis 。b_mjian=new JButton"M-"。b_mjian.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_mjian.setMarginnew Insets0,0,0,0 。b_mjian.setForegroundColor.blue 。b_mjian.addActionListenerthis 。b_tui=new JButton" "。b_tui.setFontnew Font" 微软雅黑 ",Font.BOLD,14。b_tui.setMarginnew Insets0,0,0,0 。b_tui.addActionListenerthis 。b_tui.setForegroundColor.red 。b_ce=new JButton"CE"。可编辑资料 - - - 欢迎下载精品名师归纳总结b_ce.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_ce.setMarginnew Insets0,0,0,0 。b_ce.setForegroundColor.red 。b_ce.addActionListenerthis 。b_c=new JButton"C" 。b_c.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_c.setMarginnew Insets0,0,0,0 。b_c.setForegroundColor.red 。b_c.addActionListenerthis 。b_jj=new JButton"。± "b_jj.setFontnew Font" 微软雅黑 ",Font.PLAIN,14。b_jj.setMarginnew Insets0,0,0,0 。b_jj.setForegroundColor.red 。b_jj.addActionListenerthis 。b_dui=new JButton" "。b_dui.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_dui.setMarginnew Insets0,0,0,0 。b_dui.setForegroundColor.red 。b_dui.addActionListenerthis 。b_7=new JButton"7" 。b_7.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_7.setMarginnew Insets0,0,0,0 。b_7.setForegroundColor.blue 。b_7.setMnemonicKeyEvent.VK_7 。b_7.addActionListenerthis 。b_8=new JButton"8" 。b_8.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_8.setMarginnew Insets0,0,0,0 。b_8.setForegroundColor.blue 。b_8.setMnemonicKeyEvent.VK_8 。可编辑资料 - - - 欢迎下载精品名师归纳总结b_8.addActionListenerthis 。b_9=new JButton"9" 。b_9.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_9.setMarginnew Insets0,0,0,0 。b_9.setForegroundColor.blue 。b_9.setMnemonicKeyEvent.VK_9 。b_9.addActionListenerthis 。b_chu=new JButton"/" 。b_chu.setFontnew Font" 微软雅黑 ",Font.PLAIN,14。b_chu.setMarginnew Insets0,0,0,0 。b_chu.setForegroundColor.red 。b_chu.addActionListenerthis 。b_baifenhao=new JButton"%" 。b_baifenhao.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_baifenhao.setMarginnew Insets0,0,0,0。b_baifenhao.setForegroundColor.blue 。b_baifenhao.addActionListenerthis。b_4=new JButton"4" 。b_4.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_4.setMarginnew Insets0,0,0,0 。b_4.setForegroundColor.blue 。b_4.setMnemonicKeyEvent.VK_4 。b_4.addActionListenerthis 。b_5=new JButton"5" 。b_5.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_5.setMarginnew Insets0,0,0,0 。b_5.setForegroundColor.blue 。b_5.setMnemonicKeyEvent.VK_5 。b_5.addActionListenerthis 。b_6=new JButton"6" 。可编辑资料 - - - 欢迎下载精品名师归纳总结b_6.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_6.setMarginnew Insets0,0,0,0 。b_6.setForegroundColor.blue 。b_6.setMnemonicKeyEvent.VK_6 。b_6.addActionListenerthis 。b_cheng=new JButton"*" 。b_cheng.setFontnew Font" 微软雅黑 ",Font.PLAIN,14。b_cheng.setMarginnew Insets0,0,0,0 。b_cheng.setForegroundColor.red 。b_cheng.addActionListenerthis 。b_daoshu=new JButton"1/x" 。b_daoshu.setFontnew Font" 微软雅黑 ",Font.PLAIN,11。b_daoshu.setMarginnew Insets0,0,0,0 。b_daoshu.setForegroundColor.blue 。b_daoshu.addActionListenerthis 。b_1=new JButton"1" 。b_1.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_1.setMarginnew Insets0,0,0,0 。b_1.setForegroundColor.blue 。b_1.setMnemonicKeyEvent.VK_1 。b_1.addActionListenerthis 。b_2=new JButton"2" 。b_2.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_2.setMarginnew Insets0,0,0,0 。b_2.setForegroundColor.blue 。b_2.setMnemonicKeyEvent.VK_2 。b_2.addActionListenerthis 。b_3=new JButton"3" 。b_3.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_3.setMarginnew Insets0,0,0,0 。可编辑资料 - - - 欢迎下载精品名师归纳总结b_3.setForegroundColor.blue 。b_3.setMnemonicKeyEvent.VK_3 。b_3.addActionListenerthis 。b_jian=new JButton"-" 。b_jian.setFontnew Font" 微软雅黑 ",Font.PLAIN,14。b_jian.setMarginnew Insets0,0,0,0 。b_jian.setForegroundColor.red 。b_jian.addActionListenerthis 。b_0=new JButton"0" 。b_0.setFontnew Font" 微软雅黑 ",Font.PLAIN,14 。b_0.setMarginnew Insets0,0,0,0 。b_0.setPreferredSizenew Dimension75,27 。b_0.setForegroundColor.blue 。b_0.setMnemonicKeyEvent.VK_0 。b_0.addActionListenerthis 。JLabel L1=new JLabel。L1.setPreferredSizenew Dimension5,3 。b_dian=new JButton"." 。b_dian.setFontnew Font" 微软雅黑 ",Font.BOLD,14。b_dian.setMarginnew Insets0,0,0,0 。b_dian.setPreferredSizenew Dimension35,27 。b_dian.setForegroundColor.blue 。b_dian.addActionListenerthis 。JLabel L2=new JLabel。L2.setPreferredSizenew Dimension5,3 。b_jia=new JButton"+" 。b_jia.setFontnew Font" 微软雅黑 ",Font.BOLD,14。b_jia.setMarginnew Insets0,0,0,0 。b_jia.setPreferredSizenew Dimension35,27 。b_jia.setForegroundColor.red 。可编辑资料 - - - 欢迎下载精品名师归纳总结b_jia.addActionListenerthis 。b_dengyu=new JButton"=" 。b_dengyu.setFontnew Font" 微软雅黑 ",Font.BOLD,22。b_dengyu.setMarginnew Insets0,0,0,0 。b_dengyu.setPreferredSizenew Dimension35,60 。b_dengyu.setForegroundColor.blue 。b_dengyu.addActionListenerthis 。p1.addb_mc 。p1.addb_mr 。p1.addb_ms 。p1.addb_mjia 。p1.addb_mjian 。p1.addb_tui 。p1.addb_ce 。p1.addb_c。p1.addb_jj 。p1.addb_dui 。p1.addb_7 。p1.addb_8 。p1.addb_9 。p1.addb_chu 。p1.addb_baifenhao 。p1.addb_4 。p1.addb_5 。p1.addb_6 。p1.addb_cheng 。p1.addb_daoshu 。可编辑资料 - - - 欢迎下载精品名师归纳总结p_button1.addp1 。p_button2=new JPanel 。p_button2.setPreferredSizenew Dimensionfrm.width-24,65。p_button2.setLayoutnew FlowLayoutFlowLayout.LEFT,0,0 。p_all.addp_button2 。p2=new JPanel。p2.setPreferredSizenew Dimension156,65 。p2.setLayoutnew FlowLayoutFlowLayout.LEFT,0,1 。p3=new JPanel。p3.setPreferredSizenew Dimension39,62 。p3.setLayoutnew FlowLayoutFlowLayout.LEFT,4,0 。p_button2.addp2 。p_button2.addp3 。p4=new JPanel。p4.setPreferredSizenew Dimension156,27 。p4.setLayoutnew GridLayout1,4,5,5 。p5=new JPanel。p5.setPreferredSizenew Dimension156,39 。p5.setLayoutnew FlowLayoutFlowLayout.LEFT,0,5 。p2.addp4 。p2.addp5 。可编辑资料 - - - 欢迎下载精品名师归纳总结p4.addb_1 。p4.addb_2 。p4.addb_3 。p4.addb_jian 。p5.addb_0 。p5.addL1。p5.addb_dian 。p5.addL2。p5.addb_jia 。p3.addb_dengyu 。/-快捷菜单对象 -popupmenu=new JPopupMenu 。/ 快捷菜单对象menuitem1_copy=new JMenuItem"复制"。menuitem1_copy.setAcceleratorKeyStroke.getKeyStrokeKeyEvent.VK_C,InputEvent.CTRL_MASK 。menuitem1_copy.addActionListenerthis。/监视鼠标右击菜单”复制“popupmenu.addmenuitem1_copy。menuitem1_paste=new JMenuItem"粘贴 "。menuitem1_paste.setAcceleratorKeyStroke.getKeyStrokeKeyEvent.VK_V,InputEvent.CTRL_MASK 。menuitem1_paste.addActionListenerthis。/ 监视鼠标右击菜单”粘贴“ popupmenu.addmenuitem1_paste。ta1.addpopupmenu 。con.validate 。validate 。可编辑资料 - - - 欢迎下载精品名师归纳总结/-功能区 -public void actionPerformedActionEvent e ife.getSource=menuitem_aboutJOptionPane.showMessageDialognull," 这是一个仿照 win7 的运算器!欢迎改进,n 创作者:钟作明 "," 仿 win7 运算器 ",JOptionPane.INFORMATION_MESSAGE。ife.getSource=menuitem1_copy ta1.selectAll 。ta1.copy。else ife.getSource=menuitem1_paste ta1.setEditabletrue 。ta1.setText"" 。ta1.paste 。ta1.setEditablefalse 。else ife.getSource=menuitem_copy ta1.selectAll 。ta1.copy。else ife.getSource=menuitem_paste ta1.setEditabletrue 。ta1.setText"" 。ta1.paste 。ta1.setEditablefalse 。可编辑资料 - - - 欢迎下载精品名师归纳总结else ife.getSource=menuitem_exit System.exit0。else ife.getSource=b_ce ta1.setEditabletrue 。ta1.setText"0" 。ta1.setEditablefalse 。else ife.getSource=b_cta1.setEditabletrue 。ta1.setText"0" 。ta1.setEditablefalse 。else ife.getSource=b_tuiString str=ta1.getText 。StringBuffer s=new StringBufferstr 。int L=s.length 。tryifL.=1s=s.deleteCharAtL-1。elses=new StringBuffer"0" 。catchException e1可编辑资料 - - - 欢迎下载精品名师归纳总结ta1.setTextString.valueOfs 。/-数字键 -ife.getSource=b_1addString1。else ife.getSource=b_2addString2。else ife.getSource=b_3addString3。else ife.getSource=b_4addString4。else ife.getSource=b_5addString5。else ife.getSource=b_6addString6。else ife.getSource=b_7addString7。可编辑资料 - - - 欢迎下载精品名师归纳总结else ife.getSource=b_8addString8。else ife.getSource=b_9addString9。else ife.getSource=b_0addString0。else ife.get