基于java的簡(jiǎn)易計(jì)算器的設(shè)計(jì)_第1頁(yè)
基于java的簡(jiǎn)易計(jì)算器的設(shè)計(jì)_第2頁(yè)
基于java的簡(jiǎn)易計(jì)算器的設(shè)計(jì)_第3頁(yè)
基于java的簡(jiǎn)易計(jì)算器的設(shè)計(jì)_第4頁(yè)
基于java的簡(jiǎn)易計(jì)算器的設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩23頁(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)介

1、基于java的簡(jiǎn)易計(jì)算器的設(shè)計(jì)摘要 自從java語(yǔ)言誕生以來(lái),java語(yǔ)言就以不可抵擋的趨勢(shì)很快成為國(guó)際上廣泛流行的面向?qū)ο缶幊陶Z(yǔ)言,它既具有高級(jí)語(yǔ)言的特點(diǎn),又少了C語(yǔ)言中指針特點(diǎn),因而變得簡(jiǎn)單了很多。Java是一種可以撰寫(xiě)跨平臺(tái)應(yīng)用軟件的面向?qū)ο蟮某绦蛟O(shè)計(jì)語(yǔ)言,其具有卓越的通用性、高效性、平臺(tái)移植性和安全性,廣泛應(yīng)用于個(gè)人PC、數(shù)據(jù)中心、游戲控制臺(tái)、科學(xué)超級(jí)計(jì)算機(jī)、移動(dòng)電話(huà)和互聯(lián)網(wǎng),同時(shí)擁有全球最大的開(kāi)發(fā)者專(zhuān)業(yè)社群。在全球云計(jì)算和移動(dòng)互聯(lián)網(wǎng)的產(chǎn)業(yè)環(huán)境下,Java更具備了顯著優(yōu)勢(shì)和廣闊前景。本文介紹了用java語(yǔ)言編寫(xiě)一個(gè)簡(jiǎn)易計(jì)算器。實(shí)現(xiàn)數(shù)學(xué)上的加、減、乘、除、乘方、開(kāi)方、階乘、正弦、余弦運(yùn)算

2、等相關(guān)運(yùn)算。利用這個(gè)程序可以方便的進(jìn)行日常性的小規(guī)模運(yùn)算,小巧簡(jiǎn)易,是個(gè)實(shí)用的工具。關(guān)鍵詞:程序設(shè)計(jì);簡(jiǎn)易計(jì)算器;java語(yǔ)言THE DESIGN OF SIMPLE CALCULATOR BASED ON JAVA ABSTRACTSincetheinceptionofthejavalanguage,javalanguageTakeirresistibletrendsoonbecamewidespreadinternationalpopularobject-orientedprogramminglanguage,bothwithadvancedlanguagefeatures,andless

3、oftheClanguagepointercharacteristics,andthusbecomesalotsimpler.Javaisacross-platformapplicationsoftwarecanwriteobject-orientedprogramminglanguage,whichhasexcellentversatility,efficiency,platformportability,andsecurity,arewidelyusedinpersonalPC,datacenter,gamingconsoles,scientificsuper-computers,mobi

4、lephonesandtheInternet,alsohastheworldslargestdeveloperofprofessionalcommunity.IntheglobalcloudcomputingandmobileInternetindustryenvironment,Javaandmorehavesignificantadvantagesandbroadprospects.Thisarticledescribestheusejavalanguageasimplecalculator.Achievemathematicaladdition,subtraction,multiplic

5、ation,division,involution,evolution,factorial,sine,cosineoperationsandotherrelatedoperations.Withthisprogramyoucaneasilycarryoutdailyoperationsofsmall-scale,smallsimple,isausefultool.Key words: programdesign; simple calculator; javalanguage目 錄 1 前言.1 1.1 課程設(shè)計(jì)背景.11.2 需求環(huán)境.11.3 課程設(shè)計(jì)思路.12 課程設(shè)計(jì)概要.23 計(jì)算器

6、詳細(xì)設(shè)計(jì) .3 3.1 計(jì)算器界面 . .33.1.1 CAL主類(lèi)的顯示分布.33.1.2計(jì)算器顯示界面實(shí)現(xiàn)代碼 . 33.2 監(jiān)聽(tīng)各個(gè)按鈕的類(lèi).53.2.1 編寫(xiě)監(jiān)聽(tīng)類(lèi)目的.53.2.2 監(jiān)聽(tīng)類(lèi)實(shí)現(xiàn)代碼.53.3 按鍵響應(yīng)類(lèi).73.3.1 響應(yīng)類(lèi)編寫(xiě)的目的.73.2.2 響應(yīng)類(lèi)實(shí)現(xiàn)代碼.73.3 運(yùn)算處理類(lèi).93.3.1 處理方式. .93.2.2 處理類(lèi)實(shí)現(xiàn)代碼.94 運(yùn)行與調(diào)試.12 4.1 進(jìn)入程序主界面.124.2 加減乘除功能實(shí)現(xiàn).124.3 正余弦、正切功能實(shí)現(xiàn).134.4 階乘功能實(shí)現(xiàn).134.5 乘方、開(kāi)方功能實(shí)現(xiàn).145 實(shí)驗(yàn)總結(jié).15參考文獻(xiàn).16附錄:源代碼.17 1

7、前言1.1 課程設(shè)計(jì)背景日常生活中我們經(jīng)常會(huì)遇到一些小型數(shù)據(jù)計(jì)算的問(wèn)題,本課程設(shè)計(jì)就是以此為出發(fā)點(diǎn),設(shè)計(jì)了這樣一個(gè)簡(jiǎn)單的計(jì)算器,用以實(shí)現(xiàn)基本的數(shù)學(xué)運(yùn)算。在java語(yǔ)言當(dāng)中通過(guò)定義類(lèi),類(lèi)中的各種方法實(shí)現(xiàn)對(duì)計(jì)算器相關(guān)功能的實(shí)現(xiàn),并通過(guò)與用戶(hù)自己手動(dòng)輸入并選擇運(yùn)算功能實(shí)現(xiàn)計(jì)算功能,是一個(gè)完全由用戶(hù)控制的簡(jiǎn)易計(jì)算器。在完成課程設(shè)計(jì)的期間,參閱了相關(guān)的書(shū)籍并在網(wǎng)絡(luò)上查找相關(guān)的資料,對(duì)實(shí)現(xiàn)這個(gè)設(shè)計(jì)提供了很大的幫助。由于設(shè)計(jì)水平和知識(shí)方面的匱乏,本次課程設(shè)計(jì)還存在缺點(diǎn)和不足,望多多包涵。1.2 需求環(huán)境本課程設(shè)計(jì)需要的設(shè)備為硬件要求和軟件配置要求具體要求如下:硬件要求:一臺(tái)計(jì)算機(jī)。軟件配置:WINDOWS系

8、統(tǒng)、JDK1.7、eclipse1.3課程設(shè)計(jì)思路做計(jì)算器最主要的就是實(shí)用性,要簡(jiǎn)單,便于操作。程序界面是一個(gè)窗口的形式展現(xiàn)并由用戶(hù)自己完全手動(dòng)控制。并以設(shè)計(jì)的要求為基礎(chǔ),在實(shí)現(xiàn)課程設(shè)計(jì)所給的功能以外,要對(duì)界面的美觀進(jìn)行了優(yōu)化,看起來(lái)更人性化,由此一個(gè)簡(jiǎn)潔美觀的計(jì)算器就建立起來(lái)了。2課程設(shè)計(jì)概要在設(shè)計(jì)程序的時(shí)候,考慮到計(jì)算器的功能,首先編寫(xiě)一個(gè)CAL類(lèi),在該類(lèi)中按照其功能分別寫(xiě)了一個(gè)方法實(shí)現(xiàn),在程序開(kāi)始后,可以看到一個(gè)控制面板形式的計(jì)算器界面展現(xiàn)在用戶(hù)面前,用戶(hù)自己輸入數(shù)據(jù)和選擇要運(yùn)算的功能進(jìn)行計(jì)算。具體方法有:加減乘除運(yùn)算、乘方開(kāi)方運(yùn)算、正余弦正切運(yùn)算、刪除階乘運(yùn)算等具體的關(guān)系結(jié)構(gòu)如表2-1

9、:CAL類(lèi)加、減、乘、除方法正余弦、正切方法刪除、階乘方法乘方、開(kāi)方方法表2-1 流程功能實(shí)現(xiàn)的流程圖詳解:用戶(hù)按數(shù)字鍵輸入數(shù)據(jù)加、減、乘、除方法正余弦、正切方法刪除、階乘方法乘方、開(kāi)方方法用戶(hù)啟動(dòng)計(jì)算器運(yùn)算輸出運(yùn)算結(jié)果3 計(jì)算器詳細(xì)設(shè)計(jì)3.1 計(jì)算器界面 3.1.1 CAL主類(lèi)的顯示布局為了方便用戶(hù)的使用,創(chuàng)建了一個(gè)帶按鈕的控制面板。將所有的運(yùn)算鍵、數(shù)字鍵等都放在該面板中方便用戶(hù)選擇與使用。所有的運(yùn)算選擇都完全由用戶(hù)掌控。3.1.2 計(jì)算器顯示界面實(shí)現(xiàn)代碼 程序如下:public class cal extends Applet / 定義所有需要使用的全局變量String str = 0;/

10、 暫存顯示屏數(shù)據(jù)String sign = null;/ 暫存符號(hào)數(shù)據(jù)double num = 0;/ 暫存內(nèi)部運(yùn)算數(shù)據(jù)boolean change = false;/ 暫存內(nèi)部四則運(yùn)算起用GridLayout g0, g1;/ 定義AWT布局部件JTextField number;Button num_p, num_0, num_1, num_2, num_3, num_4, num_5, num_6, num_7,num_8, num_9;Button act_add, act_mul, act_div, act_sub;Button mat_sin, mat_cos, mat_tan;B

11、utton do_ans, do_del;Button fac, sqr,inv,blank;Panel p0, p1;public void init()/ 主程序部分/ 定義各個(gè)控件的樣式number = new JTextField(20);/ 顯示屏number.setHorizontalAlignment(JTextField.RIGHT);number.setEnabled(false);number.setText(0);num_p = new Button(。);/ 小數(shù)點(diǎn)的按鈕num_p.setForeground(Color.red);num_p.addActionList

12、ener(new getbt();num_0 = new Button(0);/ 數(shù)字0的按鈕num_0.setForeground(Color.red);num_0.addActionListener(new getbt();num_1 = new Button(1);/ 數(shù)字1的按鈕num_1.setForeground(Color.red);num_1.addActionListener(new getbt();/此處省略了部分代碼num_9 = new Button(9);/ 數(shù)字9的按鈕num_9.setForeground(Color.red);num_9.addActionLis

13、tener(new getbt();act_add = new Button(+);/ 加法的按鈕act_add.setForeground(Color.red);act_add.addActionListener(new getbt();/此處省略了部分代碼blank = new Button(blank);/ blank的按鈕blank.setForeground(Color.red);blank.addActionListener(new getbt();/ 布局整個(gè)計(jì)算器g0 = new GridLayout(1, 1, 10, 10);/ 布局輸入輸出大體位置g1 = new Gri

14、dLayout(4, 6, 10, 10);p0 = new Panel(); / 顯示屏的布局p0.setLayout(g0);p0.add(number);p0.setBounds(0, 0, 100, 50);/ 按紐的布局p1 = new Panel();p1.setLayout(g1);p1.add(num_1);/ 第一排按紐p1.add(num_2);p1.add(num_3);p1.add(act_add);p1.add(act_sub);p1.add(fac);/此處省略了部分代碼p1.setBounds(5, 60, 400, 250);p1.setBackground(C

15、olor.cyan);/ 設(shè)置按鈕背景顏色setLayout(null);add(p0);add(p1);this.setBackground(Color.cyan);/ 設(shè)置背景整體顏色3.2 監(jiān)聽(tīng)各個(gè)按鈕的類(lèi) 3.2.1 編寫(xiě)監(jiān)聽(tīng)類(lèi)目的編寫(xiě)監(jiān)聽(tīng)類(lèi)的目的主要監(jiān)聽(tīng)用戶(hù)所按下的數(shù)字鍵和運(yùn)算鍵,為了計(jì)算機(jī)后續(xù)的取得數(shù)據(jù)并進(jìn)行運(yùn)算做預(yù)備工作。給后續(xù)計(jì)算工作提供保障。 3.2.2 監(jiān)聽(tīng)類(lèi)實(shí)現(xiàn)代碼class getbt implements ActionListener / 監(jiān)聽(tīng)作出反應(yīng)的類(lèi) public void actionPerformed(ActionEvent e)/ 對(duì)每個(gè)每個(gè)按鈕做出響應(yīng)i

16、f (e.getSource() = num_0)press0();else if (e.getSource() = num_1)press1();else if (e.getSource() = num_2)press2();else if (e.getSource() = num_3)press3();else if (e.getSource() = num_4)press4();else if (e.getSource() = num_5)press5();else if (e.getSource() = num_6)press6();else if (e.getSource() = n

17、um_7)press7();else if (e.getSource() = num_8)press8();else if (e.getSource() = num_9)press9();else if (e.getSource() = num_p)pressp();else if (e.getSource() = act_add)pressadd();else if (e.getSource() = act_mul)pressmul();else if (e.getSource() = act_div)pressdiv();else if (e.getSource() = act_sub)p

18、resssub();else if (e.getSource() = mat_sin)presssin();else if (e.getSource() = mat_tan)presstan();else if (e.getSource() = mat_cos)presscos();else if (e.getSource() = do_ans)pressans();else if (e.getSource() = do_del)pressdel();else if (e.getSource() = fac)pressfac();else if (e.getSource() = sqr)pre

19、sssqr();else if (e.getSource() = inv)pressinv();3.3 按鍵響應(yīng)類(lèi) 3.3.1響應(yīng)類(lèi)編寫(xiě)的目的通過(guò)監(jiān)聽(tīng)類(lèi)的監(jiān)聽(tīng),采集用戶(hù)所按下的按鍵信息進(jìn)行分析,并將分析結(jié)果保存為不同的方法和標(biāo)記,通過(guò)不同的標(biāo)記在運(yùn)算過(guò)程中調(diào)用處理類(lèi)中的不同方法實(shí)現(xiàn)計(jì)算功能。 3.3.2 響應(yīng)類(lèi)實(shí)現(xiàn)代碼public void press0()/ 對(duì)按0作出反應(yīng)if (str.length() 16 & str != 0 & change = false) str += 0; else if (str = 0 | sign != null) str = 0;number.setT

20、ext(str);/此處省略部分代碼public void pressp()/ 對(duì)按。作出反應(yīng)boolean p = false;for (int i = 0; i str.length(); i+)if (str.charAt(i) = .)p = true;if (str.length() 16)str = str.substring(0, 16);num = 0;number.setText(str);3.4 運(yùn)算處理類(lèi) 3.4.1 處理方式通過(guò)獲得上訴用戶(hù)所按下數(shù)字鍵和運(yùn)算功能鍵的信息,用響應(yīng)類(lèi)的處理結(jié)果信息進(jìn)行判斷標(biāo)示符的形式對(duì)號(hào)入座進(jìn)行調(diào)用不同運(yùn)算處理并把運(yùn)算結(jié)果顯示在輸入數(shù)據(jù)框中

21、。3.4.2 處理類(lèi)實(shí)現(xiàn)代碼public void pressans()/ 對(duì)按=作出反應(yīng)if (sign = null)number.setText(str);else if (sign = fac) int sum=1;for(int i=1;i=num;i+)sum= sum*i;str = Double.toString(sum);number.setText(str);else if (sign = sqr) double sum;sum=Math.sqrt(Double.parseDouble(str); str = Double.toString(sum);number.setT

22、ext(str);else if (sign = inv) double sum=num;for(int i=1;iDouble.parseDouble(str);i+)sum=sum*num;str = Double.toString(sum);number.setText(str);else if (sign = add) num += Double.parseDouble(str);str = Double.toString(num);number.setText(str); else if (sign = sub) num -= Double.parseDouble(str);str

23、= Double.toString(num);number.setText(str); else if (sign = mul) num *= Double.parseDouble(str);str = Double.toString(num);number.setText(str); else if (sign = div) if (num != 0) num /= Double.parseDouble(str);str = Double.toString(num);number.setText(str); else str = 0;number.setText(str);sign = nu

24、ll;4 運(yùn)行與調(diào)試 4.1 進(jìn)入程序主界面4.2 加減乘除功能實(shí)現(xiàn)例如;乘于4.3 正余弦、正切功能實(shí)現(xiàn)例如:30的tan4.4 階乘功能實(shí)現(xiàn)例如:9的階乘4.5 乘方、開(kāi)方功能實(shí)現(xiàn)例如;36開(kāi)方5 課程設(shè)計(jì)總結(jié)本次課程設(shè)計(jì)用到的是主要是java的AWT和swing這兩個(gè)類(lèi)。所應(yīng)用的開(kāi)發(fā)語(yǔ)言是Java,所采用的開(kāi)發(fā)運(yùn)行環(huán)境是:JDK + Eclipse,由于也沒(méi)有軟件項(xiàng)目的經(jīng)驗(yàn),所以做起來(lái)很吃力。要獨(dú)自編寫(xiě)計(jì)算器的各個(gè)功能,并對(duì)其進(jìn)行按鍵的排版、監(jiān)聽(tīng)、處理、運(yùn)算等各個(gè)步驟的親力親為,基本上完成了任務(wù)書(shū)上的各項(xiàng)內(nèi)容。雖然在這次的課程設(shè)計(jì)中有很多的不足,但是我也收獲了很多。設(shè)計(jì)的過(guò)程中不時(shí)地翻閱

25、資料,有時(shí)花費(fèi)一天時(shí)間就只能完成一個(gè)功能。程序代碼完成之后,要進(jìn)行運(yùn)行調(diào)試,剛開(kāi)始由于沒(méi)有調(diào)試經(jīng)驗(yàn)和方法效率很低,同時(shí)發(fā)現(xiàn)了許多錯(cuò)誤,最后在同學(xué)的幫助下,終于順利完成了,自己也從中學(xué)到了不少東西。更重要的是,在測(cè)試過(guò)程中的往往發(fā)現(xiàn)自己粗心大意犯了很多不必要的錯(cuò)誤,通過(guò)這次課程式設(shè)計(jì),我對(duì)eclipse的開(kāi)發(fā)環(huán)境有了更多的認(rèn)識(shí)和了解,讓我對(duì)java語(yǔ)言的認(rèn)識(shí)又加深了一步,不僅使我學(xué)會(huì)了如何查閱資料,同時(shí)也讓我發(fā)現(xiàn)了網(wǎng)絡(luò)這個(gè)好老師??傊斋@了很多,以后我會(huì)更努力的學(xué)習(xí)。參考文獻(xiàn)1 朱福喜.Java語(yǔ)言程序設(shè)計(jì)(第二版).科學(xué)出版社2 陳國(guó)君等.Java程序設(shè)計(jì)基礎(chǔ)(第二版).清華大學(xué)出版社3 De

26、itel.Java大學(xué)基礎(chǔ)教程(第六版).電子工業(yè)出版社 4 MaryCampione.Java語(yǔ)言導(dǎo)學(xué)(第四版).機(jī)械工業(yè)出版社5 Y.Daniel Liang.Java語(yǔ)言程序設(shè)計(jì)基礎(chǔ)篇(第六版).機(jī)械工業(yè)出版社6 Kathy Sierra.Head First Java(第二版).東南大學(xué)出版社7(美)埃克爾 著,陳昊鵬 譯 Java編程思想(第4版).機(jī)械工業(yè)出版社8 李興華 Java從入門(mén)到精通 人民郵電出版社 2010-4-1版附錄:源代碼package gefangyu;import java.applet.*;import java.awt.*;import javax.swi

27、ng.*;import java.awt.event.*;/import java.math.*;public class cal extends Applet / 定義所有需要使用的全局變量String str = 0;/ 暫存顯示屏數(shù)據(jù)String sign = null;/ 暫存符號(hào)數(shù)據(jù)double num = 0;/ 暫存內(nèi)部運(yùn)算數(shù)據(jù)boolean change = false;/ 暫存內(nèi)部四則運(yùn)算起用GridLayout g0, g1;/ 定義AWT布局部件JTextField number;Button num_p, num_0, num_1, num_2, num_3, num_

28、4, num_5, num_6, num_7,num_8, num_9;Button act_add, act_mul, act_div, act_sub;Button mat_sin, mat_cos, mat_tan;Button do_ans, do_del;Button fac, sqr,inv,blank;Panel p0, p1;public void init()/ 主程序部分/ 定義各個(gè)控件的樣式number = new JTextField(20);/ 顯示屏number.setHorizontalAlignment(JTextField.RIGHT);number.setE

29、nabled(false);number.setText(0);num_p = new Button(。);/ 小數(shù)點(diǎn)的按鈕num_p.setForeground(Color.red);num_p.addActionListener(new getbt();num_0 = new Button(0);/ 數(shù)字0的按鈕num_0.setForeground(Color.red);num_0.addActionListener(new getbt();num_1 = new Button(1);/ 數(shù)字1的按鈕num_1.setForeground(Color.red);num_1.addActi

30、onListener(new getbt();num_2 = new Button(2);/ 數(shù)字2的按鈕num_2.setForeground(Color.red);num_2.addActionListener(new getbt();num_3 = new Button(3);/ 數(shù)字3的按鈕num_3.setForeground(Color.red);num_3.addActionListener(new getbt();num_4 = new Button(4);/ 數(shù)字4的按鈕num_4.setForeground(Color.red);num_4.addActionListene

31、r(new getbt();num_5 = new Button(5);/ 數(shù)字5的按鈕num_5.setForeground(Color.red);num_5.addActionListener(new getbt();num_6 = new Button(6);/ 數(shù)字6的按鈕num_6.setForeground(Color.red);num_6.addActionListener(new getbt();num_7 = new Button(7);/ 數(shù)字7的按鈕num_p.addActionListener(new getbt();num_0 = new Button(0);/ 數(shù)字

32、0的按鈕num_0.setForeground(Color.red);num_0.addActionListener(new getbt();num_1 = new Button(1);/ 數(shù)字1的按鈕num_1.setForeground(Color.red);num_1.addActionListener(new getbt();num_2 = new Button(2);/ 數(shù)字2的按鈕num_2.setForeground(Color.red);num_2.addActionListener(new getbt();num_3 = new Button(3);/ 數(shù)字3的按鈕num_3

33、.setForeground(Color.red);num_3.addActionListener(new getbt();num_4 = new Button(4);/ 數(shù)字4的按鈕num_4.setForeground(Color.red);num_4.addActionListener(new getbt();num_5 = new Button(5);/ 數(shù)字5的按鈕num_5.setForeground(Color.red);num_5.addActionListener(new getbt();num_6 = new Button(6);/ 數(shù)字6的按鈕num_6.setForeg

34、round(Color.red);num_6.addActionListener(new getbt();num_7 = new Button(7);/ 數(shù)字7的按鈕的按鈕mat_sin.setForeground(Color.red);mat_sin.addActionListener(new getbt();mat_cos = new Button(cos);/ cos的按鈕mat_cos.setForeground(Color.red);mat_cos.addActionListener(new getbt();mat_tan = new Button(tan);/ tan的按鈕mat_

35、tan.setForeground(Color.red);mat_tan.addActionListener(new getbt();fac = new Button(fac);/ fac的按鈕fac.setForeground(Color.red);fac.addActionListener(new getbt();sqr = new Button(sqr);/ sqr的按鈕sqr.setForeground(Color.red);sqr.addActionListener(new getbt();inv= new Button(xy);/ Involution的按鈕inv.setForeg

36、round(Color.red);inv.addActionListener(new getbt();blank = new Button(blank);/ blank的按鈕blank.setForeground(Color.red);blank.addActionListener(new getbt();/ 布局整個(gè)計(jì)算器g0 = new GridLayout(1, 1, 10, 10);/ 布局輸入輸出大體位置g1 = new GridLayout(4, 6, 10, 10);p0 = new Panel(); / 顯示屏的布局p0.setLayout(g0);p0.add(number)

37、;p0.setBounds(0, 0, 100, 50);/ 按紐的布局p1 = new Panel();p1.setLayout(g1);p1.add(num_1);/ 第一排按紐p1.add(num_2);p1.add(num_3);p1.add(act_add);p1.add(act_sub);p1.add(fac);p1.add(num_4);/ 第二排按紐p1.add(num_5);p1.add(num_6);p1.add(act_mul);p1.add(act_div);p1.add(sqr);p1.add(num_7);/ 第三排按紐p1.add(num_8);p1.add(nu

38、m_9);p1.add(mat_sin);p1.add(mat_cos);p1.add(inv);p1.add(num_0);/ 第四排按鈕p1.add(num_p);p1.add(do_ans);p1.add(do_del);p1.add(mat_tan);p1.add(blank);/ 為了占位排版美觀p1.setBounds(5, 60, 400, 250);p1.setBackground(Color.cyan);/ 設(shè)置按鈕背景顏色setLayout(null);add(p0);add(p1);this.setBackground(Color.cyan);/ 設(shè)置背景整體顏色clas

39、s getbt implements ActionListener / 監(jiān)聽(tīng)作出反應(yīng)的類(lèi)public void actionPerformed(ActionEvent e)/ 對(duì)每個(gè)每個(gè)按鈕做出響應(yīng)if (e.getSource() = num_0)press0();else if (e.getSource() = num_1)press1();else if (e.getSource() = num_2)press2();else if (e.getSource() = num_3)press3();else if (e.getSource() = num_4)press4();else i

40、f (e.getSource() = num_5)press5();else if (e.getSource() = num_6)press6();else if (e.getSource() = num_7)press7();else if (e.getSource() = num_8)press8();else if (e.getSource() = num_9)press9();else if (e.getSource() = num_p)pressp();else if (e.getSource() = act_add)pressadd();else if (e.getSource()

41、 = act_mul)pressmul();else if (e.getSource() = act_div)pressdiv();else if (e.getSource() = act_sub)presssub();else if (e.getSource() = mat_sin)presssin();else if (e.getSource() = mat_tan)presstan();else if (e.getSource() = mat_cos)presscos();else if (e.getSource() = do_ans)pressans();else if (e.getS

42、ource() = do_del)pressdel();else if (e.getSource() = fac)pressfac();else if (e.getSource() = sqr)presssqr();else if (e.getSource() = inv)pressinv();public void press0()/ 對(duì)按0作出反應(yīng)if (str.length() 16 & str != 0 & change = false) str += 0; else if (str = 0 | sign != null) str = 0;number.setText(str);pub

43、lic void press1()/ 對(duì)按1作出反應(yīng)if (str.length() 16 & str != 0 & change = false) str += 1; else if (str = 0 | sign != null) str = 1;change = false;number.setText(str);public void press2()/ 對(duì)按2作出反應(yīng)if (str.length() 16 & str != 0 & change = false) str += 2; else if (str = 0 | sign != null) str = 2;change = f

44、alse;number.setText(str);public void press3()/ 對(duì)按3作出反應(yīng)if (str.length() 16 & str != 0 & change = false) str += 3; else if (str = 0 | sign != null) str = 3;change = false;number.setText(str);public void press4()/ 對(duì)按4作出反應(yīng)if (str.length() 16 & str != 0 & change = false) str += 4; else if (str = 0 | sign != null) str = 4;change = false;number.setText(str);public void press5()/ 對(duì)按5作出反應(yīng)if (str.length() 16 & str != 0 & change = false) str += 5; else i

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論