2022年java计算器源代码2.docx

上传人:Che****ry 文档编号:12791252 上传时间:2022-04-26 格式:DOCX 页数:50 大小:57.60KB
返回 下载 相关 举报
2022年java计算器源代码2.docx_第1页
第1页 / 共50页
2022年java计算器源代码2.docx_第2页
第2页 / 共50页
点击查看更多>>
资源描述

《2022年java计算器源代码2.docx》由会员分享,可在线阅读,更多相关《2022年java计算器源代码2.docx(50页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精品学习资源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,menuit

2、em1_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_d

3、ui,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;C

4、olor 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 ;/ 程序默认图标设置setIconImag

5、etk.createImageD: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标准型 ,

6、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_e

7、xit=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 ;men

8、ubar.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.getKeyStroke

9、KeyEvent.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;men

10、u_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关于

11、运算器 ;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 JTextField0 ;ta1.setFontnew Font 微软雅黑 ,Font.PLAIN,13;t

12、a1.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 FlowLayoutFlowL

13、ayout.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.setLa

14、youtnew 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 JButtonMC ;b_mc.setFontnew Font 微软雅黑 ,Font.PLAIN,11;b_mc.setMarginnew Insets0,0,0,0 ;b_mc.setForegroundColor.blue ;b_mc.addA

15、ctionListenerthis ;b_mr=new JButtonMR ;b_mr.setFontnew Font 微软雅黑 ,Font.PLAIN,11;b_mr.setMarginnew Insets0,0,0,0 ;b_mr.setForegroundColor.blue ;b_mr.addActionListenerthis ;b_ms=new JButtonMS ;b_ms.setFontnew Font 微软雅黑 ,Font.PLAIN,11;b_ms.setMarginnew Insets0,0,0,0 ;b_ms.setForegroundColor.blue ;b_ms.

16、addActionListenerthis ;b_mjia=new JButtonM+ ;b_mjia.setFontnew Font 微软雅黑 ,Font.PLAIN,11;b_mjia.setMarginnew Insets0,0,0,0 ;b_mjia.setForegroundColor.blue ;b_mjia.addActionListenerthis ;b_mjian=new JButtonM- ;b_mjian.setFontnew Font 微软雅黑 ,Font.PLAIN,11;b_mjian.setMarginnew Insets0,0,0,0;b_mjian.setFo

17、regroundColor.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 JButtonCE ;b_ce.setFontnew Font 微软雅黑 ,Font.PLAIN,11;b_ce.setMarginnew Insets0

18、,0,0,0 ;b_ce.setForegroundColor.red ;b_ce.addActionListenerthis ;b_c=new JButtonC ;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

19、 ;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 JButton7 ;b_7.setFontnew Font 微软雅黑 ,Font.PLAIN,14;b_7.setMarginnew In

20、sets0,0,0,0 ;b_7.setForegroundColor.blue ;b_7.setMnemonicKeyEvent.VK_7 ;b_7.addActionListenerthis ;b_8=new JButton8 ;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 JButton9 ;b_9.set

21、Fontnew 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.addActionListener

22、this ;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 JButton4 ;b_4.setFontnew Font 微软雅黑 ,Font.PLAIN,14;b_4.setMarginnew Insets0,0,0,0 ;b_4.setFo

23、regroundColor.blue ;b_4.setMnemonicKeyEvent.VK_4 ;b_4.addActionListenerthis ;b_5=new JButton5 ;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 JButton6 ;b_6.setFontnew Font 微软雅黑 ,Fon

24、t.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.addActionListenerth

25、is ;b_daoshu=new JButton1 /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 JButton1 ;b_1.setFontnew Font 微软雅黑 ,Font.PLAIN,14;b_1.setMarginnew Insets0,0,0,0 ;b_1.setForegroundColor.blue ;b_1

26、.setMnemonicKeyEvent.VK_1 ;b_1.addActionListenerthis ;b_2=new JButton2 ;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 JButton3 ;b_3.setFontnew Font 微软雅黑 ,Font.PLAIN,14;b_3.setMargi

27、nnew 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 JButton0 ;b_0.se

28、tFontnew 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 微软雅黑 ,

29、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

30、,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 ;

31、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_b

32、utton1.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.setPreferredSizene

33、w 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.

34、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.C

35、TRL_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.addpop

36、upmenu ;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

37、=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;els

38、e ife.getSource=b_ce ta1.setEditabletrue ;ta1.setText0 ;ta1.setEditablefalse ;else ife.getSource=b_c ta1.setEditabletrue ;ta1.setText0 ;ta1.setEditablefalse ;else ife.getSource=b_tuiString str=ta1.getText ;StringBuffer s=new StringBufferstr ;int L=s.length ;try ifL.=1s=s.deleteCharAtL-1;elses=new St

39、ringBuffer0 ;欢迎下载精品学习资源catchException e1ta1.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_5欢迎下载精品学习资源addString5 ;else ife.getSource=b_6addString6 ;else ife.getSourc

40、e=b_7addString7 ;else ife.getSource=b_8addString8 ;else ife.getSource=b_9addString9 ;else ife.getSource=b_0addString0 ;else ife.getSource=b_dianStringBuffer s1=new StringBufferta1.getText ;StringBuffer dian=new StringBuffer.;欢迎下载精品学习资源ifString.valueOfs1.indexOf.=-1 s1.appenddian ;ta1.setTextString.valueOfs1;else ife.getSource=b_jjString txt=ta1.getText ;int

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁