java计算器源代码仿winWord下载.docx
《java计算器源代码仿winWord下载.docx》由会员分享,可在线阅读,更多相关《java计算器源代码仿winWord下载.docx(18页珍藏版)》请在冰点文库上搜索。
super(s)。
setSize(220,315)。
setResizable(false)。
setVisible(true)。
Dimensionscr=Toolkit.getDefaultToolkit().getScreenSize()。
Dimensionfrm=this.getSize()。
setLocation((scr.width-frm.width)/2,(scr.height-frm.height)/2)。
Toolkittk=Toolkit.getDefaultToolkit()。
//程序默认图标设置
setIconImage(tk.createImage("
D:
\\sd.jpg"
))。
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)。
//-----------------------------------------------------------------制作框架结构-------------------------
//---------------------------------------菜单栏---------------------------
menubar=newJMenuBar()。
menubar.setPreferredSize(newDimension(frm.width,19))。
menu_check=newJMenu("
查看(V)"
)。
menu_check.setFont(font)。
menu_check.setForeground(Color.black)。
menuitem_standard=newJCheckBoxMenuItem("
标准型"
true)。
menuitem_standard.setFont(font)。
menuitem_standard.setForeground(Color.black)。
menuitem_science=newJMenuItem("
科学型"
menuitem_science.setFont(font)。
menuitem_science.setForeground(Color.black)。
menuitem_check=newJMenuItem("
查看分组"
menuitem_check.setFont(font)。
menuitem_check.setForeground(Color.black)。
menuitem_exit=newJMenuItem("
退出"
menuitem_exit.setFont(font)。
menuitem_exit.setForeground(Color.black)。
menuitem_exit.addActionListener(this)。
menu_check.add(menuitem_standard)。
menu_check.add(menuitem_science)。
menu_check.addSeparator()。
menu_check.add(menuitem_check)。
menu_check.add(menuitem_exit)。
menubar.add(menu_check)。
menu_edit=newJMenu("
编辑(E)"
menu_edit.setFont(font)。
menu_edit.setForeground(Color.black)。
menu_edit.setMnemonic(KeyEvent.VK_E)。
menuitem_copy=newJMenuItem("
复制(C)"
menuitem_copy.setFont(font)。
menuitem_copy.setForeground(Color.black)。
menuitem_copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK))。
menuitem_copy.addActionListener(this)。
menuitem_paste=newJMenuItem("
粘贴(P)"
menuitem_paste.setFont(font)。
menuitem_paste.setForeground(Color.black)。
menuitem_paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK))。
menuitem_paste.addActionListener(this)。
menu_edit.add(menuitem_copy)。
menu_edit.add(menuitem_paste)。
menubar.add(menu_edit)。
menu_help=newJMenu("
帮助(H)"
menu_help.setFont(font)。
menu_help.setForeground(Color.black)。
menuitem_chelp=newJMenuItem("
查看帮助"
menuitem_chelp.setFont(font)。
menuitem_chelp.setForeground(Color.black)。
menuitem_about=newJMenuItem("
关于计算器"
menuitem_about.setFont(font)。
menuitem_about.setForeground(Color.black)。
menuitem_about.addActionListener(this)。
menu_help.add(menuitem_chelp)。
menu_help.addSeparator()。
menu_help.add(menuitem_about)。
menubar.add(menu_help)。
setJMenuBar(menubar)。
//--------------------------------------文本框----------------------------------
ta1=newJTextField("
0"
ta1.setFont(newFont("
Font.PLAIN,13))。
ta1.setEditable(false)。
//ta1.setOpaque(false)。
ta1.setHorizontalAlignment(JTextField.RIGHT)。
ta1.setPreferredSize(newDimension((frm.width-26),45))。
ta1.addMouseListener(this)。
p_all=newJPanel()。
p_all.setPreferredSize(newDimension((frm.width-6),250))。
//p_all.setBackground(color)。
p_all.setLayout(newFlowLayout(FlowLayout.CENTER,0,3))。
p_txt=newJPanel()。
p_txt.setPreferredSize(newDimension((frm.width-6),53))。
p_txt.setLayout(newFlowLayout(FlowLayout.CENTER,0,7))。
p_txt.add(ta1)。
p_all.add(p_txt)。
con.add(p_all,BorderLayout.CENTER)。
//-------------------------------------按钮区----------------------------------
p_button1=newJPanel()。
p_button1.setPreferredSize(newDimension((frm.width-25),131))。
p_button1.setLayout(newFlowLayout(FlowLayout.LEFT,0,3))。
p_all.add(p_button1)。
p1=newJPanel()。
p1.setPreferredSize(newDimension((frm.width-25),127))。
p1.setLayout(newGridLayout(4,5,5,6))。
b_mc=newJButton("
MC"
b_mc.setFont(newFont("
Font.PLAIN,11))。
b_mc.setMargin(newInsets(0,0,0,0))。
b_mc.setForeground(Color.blue)。
b_mc.addActionListener(this)。
b_mr=newJButton("
MR"
b_mr.setFont(newFont("
b_mr.setMargin(newInsets(0,0,0,0))。
b_mr.setForeground(Color.blue)。
b_mr.addActionListener(this)。
b_ms=newJButton("
MS"
b_ms.setFont(newFont("
b_ms.setMargin(newInsets(0,0,0,0))。
b_ms.setForeground(Color.blue)。
b_ms.addActionListener(this)。
b_mjia=newJButton("
M+"
b_mjia.setFont(newFont("
b_mjia.setMargin(newInsets(0,0,0,0))。
b_mjia.setForeground(Color.blue)。
b_mjia.addActionListener(this)。
b_mjian=newJButton("
M-"
b_mjian.setFont(newFont("
b_mjian.setMargin(newInsets(0,0,0,0))。
b_mjian.setForeground(Color.blue)。
b_mjian.addActionListener(this)。
b_tui=newJButton("
←"
b_tui.setFont(newFont("
Font.BOLD,14))。
b_tui.setMargin(newInsets(0,0,0,0))。
b_tui.addActionListener(this)。
b_tui.setForeground(Color.red)。
b_ce=newJButton("
CE"
b_ce.setFont(newFont("
b_ce.setMargin(newInsets(0,0,0,0))。
b_ce.setForeground(Color.red)。
b_ce.addActionListener(this)。
b_c=newJButton("
C"
b_c.setFont(newFont("
b_c.setMargin(newInsets(0,0,0,0))。
b_c.setForeground(Color.red)。
b_c.addActionListener(this)。
b_jj=newJButton("
±
"
b_jj.setFont(newFont("
Font.PLAIN,14))。
b_jj.setMargin(newInsets(0,0,0,0))。
b_jj.setForeground(Color.red)。
b_jj.addActionListener(this)。
b_dui=newJButton("
√"
b_dui.setFont(newFont("
b_dui.setMargin(newInsets(0,0,0,0))。
b_dui.setForeground(Color.red)。
b_dui.addActionListener(this)。
b_7=newJButton("
7"
b_7.setFont(newFont("
b_7.setMargin(newInsets(0,0,0,0))。
b_7.setForeground(Color.blue)。
b_7.setMnemonic(KeyEvent.VK_7)。
b_7.addActionListener(this)。
b_8=newJButton("
8"
b_8.setFont(newFont("
b_8.setMargin(newInsets(0,0,0,0))。
b_8.setForeground(Color.blue)。
b_8.setMnemonic(KeyEvent.VK_8)。
b_8.addActionListener(this)。
b_9=newJButton("
9"
b_9.setFont(newFont("
b_9.setMargin(newInsets(0,0,0,0))。
b_9.setForeground(Color.blue)。
b_9.setMnemonic(KeyEvent.VK_9)。
b_9.addActionListener(this)。
b_chu=newJButton("
/"
b_chu.setFont(newFont("
b_chu.setMargin(newInsets(0,0,0,0))。
b_chu.setForeground(Color.red)。
b_chu.addActionListener(this)。
b_baifenhao=newJButton("
%"
b_baifenhao.setFont(newFont("
b_baifenhao.setMargin(newInsets(0,0,0,0))。
b_baifenhao.setForeground(Color.blue)。
b_baifenhao.addActionListener(this)。
b_4=newJButton("
4"
b_4.setFont(newFont("
b_4.setMargin(newInsets(0,0,0,0))。
b_4.setForeground(Color.blue)。
b_4.setMnemonic(KeyEvent.VK_4)。
b_4.addActionListener(this)。
b_5=newJButton("
5"
b_5.setFont(newFont("
b_5.setMargin(newInsets(0,0,0,0))。
b_5.setForeground(Color.blue)。
b_5.setMnemonic(KeyEvent.VK_5)。
b_5.addActionListener(this)。
b_6=newJButton("
6"
b_6.setFont(newFont("
b_6.setMargin(newInsets(0,0,0,0))。
b_6.setForeground(Color.blue)。
b_6.setMnemonic(KeyEvent.VK_6)。
b_6.addActionListener(this)。
b_cheng=newJButton("
*"
b_cheng.setFont(newFont("
b_cheng.setMargin(newInsets(0,0,0,0))。
b_cheng.setForeground(Color.red)。
b_cheng.addActionListener(this)。
b_daoshu=newJButton("
1/x"
b_daoshu.setFont(newFont("
b_daoshu.setMargin(newInsets(0,0,0,0))。
b_daoshu.setForeground(Color.blue)。
b_daoshu.addActionListener(this)。
b_1=newJButton("
1"
b_1.setFont(newFont("
b_1.setMargin(newInsets(0,0,0,0))。
b_1.setForeground(Color.blue)。
b_1.setMnemonic(KeyEvent.VK_1)。
b_1.addActionListener(this)。
b_2=newJButton("
2"
b_2.setFont(newFont("
b_2.setMargin(newInsets(0,0,0,0))。
b_2.setForeground(Color.blue)。
b_2.setMnemonic(KeyEvent.VK_2)。
b_2.addActionListener(this)。
b_3=newJButton("
3"
b_3.setFont(newFont("
b_3.setMargin(newInsets(0,0,0,0))。
b_3.setForeground(Color.blue)。
b_3.setMnemonic(KeyEvent.VK_3)。
b_3.addActionListener(this)。
b_jian=newJButton("
-"
b_jian.setFont(newFont("
b_jian.setMargin(newInsets(0,0,0,0))。
b_jian.setForeground(Color.red)。
b_jian.addActionListener(this)。
b_0=newJButton("
b_0.setFont(newFont("
b_0.setMargin(newInsets(0,0,0,0))。
b_0.setPreferredSize(newDimension(75,27))。