




已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
java計(jì)算器實(shí)現(xiàn)源代碼上傳.txt性格本身沒(méi)有好壞,樂(lè)觀和悲觀對(duì)這個(gè)世界都有貢獻(xiàn),前者發(fā)明了飛機(jī),后者發(fā)明了降落傘。import java.awt.*;import java.awt.event.*;import javax.swing.*;public class testpublic static void main(String args )jisuan frame = new jisuan();/新建一個(gè)jisuan類(lèi)對(duì)象frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/為該對(duì)象設(shè)置默認(rèn)關(guān)閉動(dòng)作frame.setResizable(false);/設(shè)置不可調(diào)整大小frame.show();/將該框架對(duì)象顯示出來(lái)class jisuan extends JFrame implements ActionListener/jisuan類(lèi)繼承自JFrame類(lèi)private JMenuBar menubar = new JMenuBar();private JMenu m1 = new JMenu(文件(field);private JMenu m2 = new JMenu(編輯(education);private JMenu m3 = new JMenu(幫助(help);/新建菜單欄private JMenuItem t2,t3,t4,t7,t8;private JPanel j1,j2;private JButton b0,b1,b2,b3,b4,b5,b6,b7,b8,b9;private JButton kaigen,qiuyu,pingfang,zengxuan,yuxuan ,jiecheng,jia,jian,cheng,chu,dengyu;private Container contenPane = this.getContentPane();/獲取當(dāng)前的內(nèi)容窗格private JTextField p1,p2;private JLabel j0;private double tem1 = 0;private double tem2 = 0;private double tem3 = 0;private int biaozhi=0;public jisuan() /構(gòu)造函數(shù)super.setTitle(簡(jiǎn)單計(jì)算器);/設(shè)置標(biāo)題super.setSize(640,200);/設(shè)置尺寸super.setJMenuBar(menubar);menubar.add(m1);menubar.add(m2);menubar.add(m3);t2 = new JMenuItem(全部清零);t3 = new JMenuItem(打開(kāi)圓周率);t4 = new JMenuItem(退出);m1.add(t2);m1.add(t3);m1.add(t4);t7 = new JMenuItem(寫(xiě)字本);m2.add(t7);t8 = new JMenuItem(關(guān)于.);m3.add(t8);j1 = new JPanel();p1 = new JTextField(40);p1.setEditable(false);j0 = new JLabel(請(qǐng)輸入要計(jì)算的數(shù)字:);/ p2 = new JTextField(請(qǐng)輸入計(jì)算的數(shù)字,10);/ p3 = new JTextField(結(jié)果是,10);/ p3.setEditable(false);j1.add(j0);j1.add(p1);/ j1.add(p2);/ j1.add(p3);j2 = new JPanel();GridLayout f = new GridLayout(3,7);/新建一個(gè)布局管理器對(duì)象j2.setLayout(f);/將布局管理器對(duì)象加入到面板中b0 = new JButton(0);b1 = new JButton(1);b2 = new JButton(2);b3 = new JButton(3);b4 = new JButton(4);b5 = new JButton(5);b6 = new JButton(6);b7 = new JButton(7);b8 = new JButton(8);b9 = new JButton(9);/ j3 = new JPanel();j2.add(b0);j2.add(b1);j2.add(b2);j2.add(b3);j2.add(b4);j2.add(b5);j2.add(b6);j2.add(b7);j2.add(b8);j2.add(b9);jia = new JButton(+);jian = new JButton(-);cheng = new JButton(*);chu = new JButton(/);kaigen = new JButton(立方根);qiuyu = new JButton(平方根);pingfang = new JButton(平方);zengxuan = new JButton(sin);yuxuan = new JButton(cos);jiecheng = new JButton(階乘);dengyu = new JButton(=);j2.add(jia);j2.add(jian);j2.add(cheng);j2.add(chu);j2.add(kaigen);j2.add(qiuyu);j2.add(pingfang);j2.add(zengxuan);j2.add(yuxuan);j2.add(jiecheng);j2.add(dengyu);contenPane.add(j2,BorderLayout.CENTER);/將j2添加到內(nèi)容窗格中同時(shí)為其指定位置contenPane.add(j1,BorderLayout.NORTH);b0.addActionListener(this);b1.addActionListener(this);b2.addActionListener(this);b3.addActionListener(this);b4.addActionListener(this);b5.addActionListener(this);b6.addActionListener(this);b7.addActionListener(this);b8.addActionListener(this);b9.addActionListener(this);jia.addActionListener(this);jian.addActionListener(this);cheng.addActionListener(this);chu.addActionListener(this);kaigen.addActionListener(this);qiuyu.addActionListener(this);pingfang.addActionListener(this);zengxuan.addActionListener(this);yuxuan.addActionListener(this);jiecheng.addActionListener(this);dengyu.addActionListener(this);/為按鈕添加事件監(jiān)聽(tīng)器t2.addActionListener(this);t3.addActionListener(this);t4.addActionListener(this);t7.addActionListener(this);t8.addActionListener(this);/JMenuItem類(lèi)對(duì)象添加事件監(jiān)聽(tīng)器public void actionPerformed(ActionEvent e)if(e.getSource()=b0)p1.setText(0);j1.add(p1);tem1 = 0;else if(e.getSource() = b1)p1.setText(1);j1.add(p1);tem1 = 1;else if(e.getSource() = b2)p1.setText(2);j1.add(p1);tem1 = 2;else if(e.getSource() = b3)p1.setText(3);j1.add(p1);tem1 = 3;else if(e.getSource() = b4)p1.setText(4);j1.add(p1);tem1 = 4;else if(e.getSource() = b5)p1.setText(5);j1.add(p1);tem1 = 5;else if(e.getSource() = b6)p1.setText(6);j1.add(p1);tem1 = 6;else if(e.getSource() = b7)p1.setText(7);j1.add(p1);tem1 = 7;else if(e.getSource() = b8)p1.setText(8);j1.add(p1);tem1 = 8;else if(e.getSource() = b9)p1.setText(9);j1.add(p1);tem1 = 9;if(e.getSource()=jia)p1.setText(tem1+);j1.add(p1);tem2 = tem1;biaozhi = 0; if(e.getSource()=jian)p1.setText(tem1+-);j1.add(p1);tem2 = tem1;biaozhi = 1;if(e.getSource()=cheng)p1.setText(tem1+*);j1.add(p1);tem2 = tem1;biaozhi = 2;if(e.getSource()=chu)p1.setText(tem1+/);j1.add(p1);tem2 = tem1;biaozhi = 3; if(e.getSource()=kaigen) p1.setText(tem1+立方根); j1.add(p1); tem2 = tem1; biaozhi = 4; if(e.getSource()=qiuyu) p1.setText(tem1+平方根); j1.add(p1); tem2 = tem1; biaozhi = 5; if(e.getSource()=pingfang) p1.setText(tem1+平方); j1.add(p1); tem2 = tem1; biaozhi = 6; if(e.getSource()=zengxuan) p1.setText(tem1+sina); j1.add(p1); tem2 = tem1; biaozhi = 7; if(e.getSource()=yuxuan) p1.setText(tem1+cosa); j1.add(p1); tem2 = tem1; biaozhi = 8; if(e.getSource()=jiecheng) p1.setText(tem1+!); j1.add(p1); tem2 = tem1; biaozhi = 9; if(e.getSource()=dengyu) if(biaozhi =0) tem3 = tem2+tem1; if(biaozhi =1) tem3 = tem2-tem1; if(biaozhi =2) tem3 = tem2*tem1; if(biaozhi =3) tem3 = tem2/tem1; if(biaozhi =4) tem3 =Math.cbrt(tem1); if(biaozhi =5) tem3 =Math.sqrt(tem1); if(biaozhi =6) tem3 = tem1*tem1; if(biaozhi =7) tem3 = Math.sin(tem1); if(biaozhi =8) tem3 = Math.cos(tem1); if(biaozhi =9) tem3 = jisuanjiecheng(tem1); p1.setText(=+tem3); j1.add(p1); else if(e.getSource()=t2) p1.setText(0.0); j1.add(p1); else if(e.getSource()=t3) p1.setText(Math.PI+); j1.add(p1); else if(e.getSource()=t4) System.exit(0); else if(e.getSource()=t8) helpFile myhelpfile=new helpFile(); myhelpfile.show(); else if(e.getSource()=t7) repaint(); jishiben mynewjisuan=new jishiben(); mynewjisuan.show(); /實(shí)現(xiàn)監(jiān)聽(tīng)器 private double jisuanjiecheng(double a) if(a=1) return 1;/遞歸出口 else return (jisuanjiecheng(a-1)*a);/實(shí)現(xiàn)遞歸計(jì)算階乘 class jishiben extends JFrame/實(shí)現(xiàn)記事本類(lèi) private Container contenPane1 = getContentPane(); private JTextArea text = new JTextArea(); private JButton tuibutton; private JPanel ji1,ji2; public jishiben() super.setTitle(文本編輯器);/設(shè)置標(biāo)題 super.setSize(300,200);/設(shè)置尺寸 ji1 = new JPanel(); ji2 = new JPanel(); text = new JTextArea(請(qǐng)輸入你要記錄的文字,7,20);/行數(shù)為5列數(shù)為20 text.setLineWrap(true);/為文本框設(shè)置可回繞,即滿(mǎn)行之后自動(dòng)實(shí)現(xiàn)換行 tuibutton = new JButton(退出); tuibutton.addActionListener(new tuiActionListener(); ji1.add(text); ji2.add(tuibutton); contenPane1.add(ji2,BorderLayout.SOUTH); contenPane1.add(ji1,BorderLayout.NORTH); private class tuiActionListener implements ActionListener public void actionPerformed(ActionEvent e) setVisible(false); class helpFile extends JFrame/實(shí)現(xiàn)幫助文檔類(lèi) private Container contenPane1 = getContentPane(); private JTextArea text = new
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 藥劑學(xué)試題庫(kù)及答案
- 生活中的圓文化課件
- 銷(xiāo)售部安全試題及答案
- 2025年秋統(tǒng)編版七年級(jí)語(yǔ)文上冊(cè) 第一學(xué)期期中測(cè)試卷
- 項(xiàng)目合作意向書(shū)合集15篇
- 生殖健康課件教學(xué)
- 2018-2022北京高中合格考生物匯編:細(xì)胞的能量供應(yīng)和利用
- 鍋爐破損維修方案(3篇)
- 店鋪圍欄改造方案(3篇)
- 提升員工服務(wù)方案(3篇)
- 部編 人教版四年級(jí)語(yǔ)文下冊(cè)全冊(cè)課內(nèi)閱讀理解練習(xí)(含答案)
- 工程建設(shè)管理工作報(bào)告
- 攪拌站環(huán)境管理制度
- 江蘇省蘇州市相城區(qū)2024年五年級(jí)數(shù)學(xué)第二學(xué)期期末調(diào)研試題含解析
- 礦山企業(yè)會(huì)議管理制度
- 人教版七年級(jí)下冊(cè)英語(yǔ)單詞變形
- 廣東中山市2023-2024學(xué)年三年級(jí)數(shù)學(xué)第二學(xué)期期末學(xué)業(yè)水平測(cè)試試題含解析
- (高清版)AQ 1056-2008 煤礦通風(fēng)能力核定標(biāo)準(zhǔn)
- 《學(xué)前兒童健康教育》6-2學(xué)前兒童安全教育的目標(biāo)和內(nèi)容課件
- 《建筑施工塔式起重機(jī)安裝、使用、拆卸安全技術(shù)規(guī)程》(JGJ196-2010)
- 2024年陜西初中地理學(xué)業(yè)水平考試試卷答案講解課件
評(píng)論
0/150
提交評(píng)論