Java課程設(shè)計(jì)報(bào)告-計(jì)算器,輸入輸出流讀取iris.txt文件,黃金卡,多線程動(dòng)畫,記事本_第1頁
Java課程設(shè)計(jì)報(bào)告-計(jì)算器,輸入輸出流讀取iris.txt文件,黃金卡,多線程動(dòng)畫,記事本_第2頁
Java課程設(shè)計(jì)報(bào)告-計(jì)算器,輸入輸出流讀取iris.txt文件,黃金卡,多線程動(dòng)畫,記事本_第3頁
Java課程設(shè)計(jì)報(bào)告-計(jì)算器,輸入輸出流讀取iris.txt文件,黃金卡,多線程動(dòng)畫,記事本_第4頁
Java課程設(shè)計(jì)報(bào)告-計(jì)算器,輸入輸出流讀取iris.txt文件,黃金卡,多線程動(dòng)畫,記事本_第5頁
已閱讀5頁,還剩31頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、JAVA課程設(shè)計(jì)一、實(shí)驗(yàn)?zāi)康模ㄐ∷奶?hào)宋體加粗)通過課程設(shè)計(jì),主要要達(dá)到兩個(gè)目的,一是檢驗(yàn)和鞏固專業(yè)知識(shí)、二是提高綜合素質(zhì)和能力。信科09級(jí)學(xué)生的課程設(shè)計(jì)主要是Java語言程序設(shè)計(jì)的實(shí)現(xiàn)。通過該課程設(shè)計(jì),可以將學(xué)生課堂上掌握的理論知識(shí)與處理數(shù)據(jù)的業(yè)務(wù)相結(jié)合,以檢驗(yàn)我們同學(xué)們掌握知識(shí)的寬度、深度及對(duì)知識(shí)的綜合運(yùn)用能力。二、實(shí)驗(yàn)環(huán)境(如軟硬件)CPU:Inter(R) Pentium(R) CPU P6000 ;顯卡:NVIDIA GeForce 310M;硬盤:320G;內(nèi)存:2G;操作系統(tǒng):Windows 7;編譯器:JDK三、實(shí)驗(yàn)內(nèi)容1、內(nèi)容一 設(shè)計(jì)一個(gè)計(jì)算器,利用它可以進(jìn)行簡單的四則運(yùn)算(加

2、、減、乘、除、開方)等,但僅限于十進(jìn)制下,此外還可以進(jìn)行(八進(jìn)制,十進(jìn)制,十六進(jìn)制)之間的相互轉(zhuǎn)換。要求:有簡單的需求分析,功能設(shè)計(jì),詳細(xì)設(shè)計(jì)(程序流程),異常處理,測(cè)試,源程序清單,總結(jié),具體格式見附件。知識(shí)點(diǎn):掌握 圖形用戶界面設(shè)計(jì); 掌握基本類的設(shè)計(jì)與使用; 掌握事件處理機(jī)制; 掌握使用異常處理方法。 2、文件的分割符)知識(shí)點(diǎn): 掌握使用JAVA的輸入輸出流掌握使用String類以及和基本數(shù)據(jù)類型的轉(zhuǎn)換。3、內(nèi)容三 “湖南經(jīng)視臺(tái)猜“黃金卡”節(jié)目簡介如下: 有三張卡,其中兩張銀卡,一張黃金卡,放在把背面提供給競猜者來猜,本節(jié)目存在三種選擇方法。方法一:在競猜者隨機(jī)三選一后,不再改變選擇的結(jié)

3、果;方法二:在競猜者隨機(jī)三選一后,主持人再翻開剩下兩張中沒有被選中的一張銀卡,競猜者再重新在剩下的兩張卡中隨機(jī)選擇。方法三:在競猜者隨機(jī)三選一后,主持人再翻開剩下兩張中沒有被選中的一張銀卡,競猜者改變?cè)瓉淼倪x擇,選取剩下的唯一那張沒有翻開的卡。要求:(1) 請(qǐng)用圖形用戶界面設(shè)計(jì)方法一的競猜過程,(2) 利用蒙特卡洛仿真方法驗(yàn)證湖南經(jīng)視臺(tái)猜“黃金卡”節(jié)目三種不同方法的優(yōu)劣。知識(shí)點(diǎn):掌握事件處理機(jī)制;掌握隨機(jī)采樣的方法;掌握?qǐng)D形用戶界面設(shè)計(jì);(注:采用圖形用戶方式設(shè)計(jì))4、內(nèi)容四 :設(shè)計(jì)一個(gè)記事本,菜單中要求有文件,編輯,和幫助。文件中有新建、打開、保存和退出;編輯中有剪切、復(fù)制和粘貼;幫助中顯示

4、開發(fā)人和版本信息。知識(shí)點(diǎn): 掌握 圖形用戶界面設(shè)計(jì); 掌握基本類的設(shè)計(jì)與菜單設(shè)計(jì); 掌握事件處理機(jī)制; 掌握使用異常處理方法。5、 內(nèi)容五:一個(gè)多線程的動(dòng)畫知識(shí)點(diǎn):Java中線程的實(shí)現(xiàn);線程的優(yōu)先級(jí)、調(diào)度與同步;設(shè)計(jì)步驟:窗口布局設(shè)計(jì)設(shè)計(jì)線程類MainPanel類的設(shè)計(jì)實(shí)驗(yàn)效果為:程序功能:每點(diǎn)擊一次“Start”按鈕,就會(huì)在畫面上出現(xiàn)一個(gè)新的小球。這些小球按照一定的線路移動(dòng),而且小球的移動(dòng)速度是相同的。四、算法分析、設(shè)計(jì)與描述1.算法分析、設(shè)計(jì)內(nèi)容一:首先,完成計(jì)算器界面的設(shè)計(jì),構(gòu)造Calculator類,申明基本屬性,包括框架屬性和按鈕屬性。另外在構(gòu)造器中完成界面布局和各種按鈕以及文本框的

5、初始化,并且添加事件響應(yīng)。其次在構(gòu)造方法中,使用String數(shù)組存儲(chǔ)每個(gè)按鈕的名稱,同時(shí)使用for循環(huán)完成每個(gè)按鈕的顯示初始化。最后在寫出各事件,如數(shù)字事件、符號(hào)事件、等號(hào)事件,并寫出各類運(yùn)算函數(shù),如加法、減法、乘法、除法,最后于主函數(shù)中調(diào)用各功能及運(yùn)算內(nèi)容二:并對(duì)此文件的每列元素進(jìn)行處理(求和、求平均值)。為保證讀取文件的正確性,采用字符流讀取文件,然后再按行讀取,讀取一行處理一行。內(nèi)容三:本程序算法要實(shí)現(xiàn)模擬黃金卡猜選的第一種方法,并且要通過蒙特卡羅仿真法比較三種方法的優(yōu)劣。該算法主要是Math類產(chǎn)生隨機(jī)數(shù)方法的運(yùn)用。通過Jframe進(jìn)行布局分別用,并統(tǒng)計(jì)出三種猜測(cè)方法的猜中次數(shù)以及概率。

6、模擬方法一:采用產(chǎn)生隨機(jī)數(shù)的方法并判斷兩次產(chǎn)生的隨機(jī)數(shù)是否相等,若相等則猜中,若不等則相反,并根據(jù)實(shí)驗(yàn)次數(shù)得出最后的正確結(jié)果的概率與次數(shù)。內(nèi)容四:在算法設(shè)計(jì)上,先設(shè)計(jì)出計(jì)算器面板,菜單放在菜單條里,菜單項(xiàng)放在菜單里,在本程序中,設(shè)計(jì)了一個(gè)菜單欄和文本區(qū),設(shè)計(jì)過程中用到了JScrollPane,JMenu,JTextPane, JMenuBar用來用菜單,菜單包括“文件”“編輯”“幫助”, JMenuItem用來用菜單子項(xiàng),JTextPane主要用來輸入文本。內(nèi)容五:在本程序中,創(chuàng)建一個(gè)窗體對(duì)象,把小球所在的內(nèi)容面板添加到窗體中,把按鈕所在的面板添加到內(nèi)容面板的下方。創(chuàng)建一個(gè)線程類,創(chuàng)建了小球?qū)?/p>

7、象的同時(shí),創(chuàng)建并啟動(dòng)線程。以實(shí)現(xiàn)多線程動(dòng)畫的操作。2算法描述(可插入流程圖)內(nèi)容一:用switch語句判斷點(diǎn)擊的是什么類型的按鈕,是數(shù)字鍵則接受數(shù)字到輸入框,是運(yùn)算符則執(zhí)行相應(yīng)的運(yùn)算,加減乘除算法的描述:用switch語句判斷點(diǎn)擊的是何種算法,定義一個(gè)變量mark存放運(yùn)算符,實(shí)現(xiàn)對(duì)應(yīng)的運(yùn)算。進(jìn)制轉(zhuǎn)換算法描述:用if語句判斷選中的進(jìn)制對(duì)應(yīng)的選擇框(默認(rèn)選中的是十進(jìn)制),并對(duì)該事件做對(duì)應(yīng)的按鈕處理,用變量length判斷上次選中的是哪個(gè)進(jìn)制的選擇框,用來進(jìn)行相互轉(zhuǎn)換,然后進(jìn)行運(yùn)算。假如是非十進(jìn)制,則先轉(zhuǎn)化成十進(jìn)制,然后再轉(zhuǎn)化成需要的進(jìn)制。內(nèi)容二:用while循環(huán)對(duì)文件按行讀取存放到字符型變量s里,

8、只要s不為null則循環(huán),在循環(huán)里加一個(gè)計(jì)數(shù)器count,用于記錄文件的行數(shù)用于求平均值,每行按分隔符t進(jìn)行行的分割,把每行的第i個(gè)元素累加到浮點(diǎn)型數(shù)組sumi里,讀取完后在進(jìn)行求平均值的運(yùn)算。最后打印出每列總和及每列平均值。內(nèi)容三:按鈕界面:黃金卡中要設(shè)計(jì)到相應(yīng)的一個(gè)開始游戲的按鈕和一個(gè)重新開始的按鈕,我采用的是JButton,分別建立的一個(gè)有“開始”和“重玩”文字的按鈕。文本框設(shè)計(jì):用JTextField來構(gòu)建相應(yīng)的文本框,用JTextField()來構(gòu)建單行文本框,以滿足程序的要求和圖形設(shè)計(jì)。顏色背景及字體的設(shè)定:JLabel 對(duì)象可以顯示文本、圖像或同時(shí)顯示二者。內(nèi)容四:記事本設(shè)計(jì)圖如

9、下,前先要?jiǎng)?chuàng)建一個(gè)Jishiben的類繼承JFrame類作為最底層的容器。在構(gòu)建Jishiben類時(shí)要初使化容器,初使化組件。內(nèi)容五: 事件的面板要有兩個(gè)按鈕,Start按鈕用來創(chuàng)建小球和啟動(dòng)線程,Close按鈕用來關(guān)閉窗口結(jié)束進(jìn)程。程序中小球類(Class Ball)有多個(gè)方法:Ball()構(gòu)建小球的方法;draw()畫填充小球的方法;move()小球移動(dòng)的方法,當(dāng)小球移動(dòng)到屏幕邊界則反彈。循環(huán)對(duì)線程進(jìn)行處理:每隔5毫秒運(yùn)行一次。運(yùn)行一次小球前進(jìn)一個(gè)像素。五、程序設(shè)計(jì)1程序設(shè)計(jì)的基本思路內(nèi)容一:先在主函數(shù)里把計(jì)算器的布局寫好,然后寫一個(gè)設(shè)置各個(gè)按鈕行為的方法,在這個(gè)方法里給出一個(gè)最初發(fā)生的E

10、vent對(duì)象,由它來判斷鼠標(biāo)點(diǎn)擊算法操作(加、減、乘除等),判斷好了,然后就把文本框制空,然后定義一個(gè)int變量mark,mark用來保存當(dāng)前進(jìn)行何種運(yùn)算。用戶另輸數(shù)字,點(diǎn)擊“=” 在“=”操作里判斷mark值,根據(jù)mark值判斷是哪種算法,然后算出來,把結(jié)果射入文本框中,在文本框不為空時(shí),改變進(jìn)制選擇框,則進(jìn)行進(jìn)制轉(zhuǎn)換,把結(jié)果射入文本框中。內(nèi)容二:在主函數(shù)里把要用到的變量定義好,然后嘗試開始讀取文件,并對(duì)讀取的數(shù)據(jù)相應(yīng)的進(jìn)行處理,若讀取失敗則打印“文件讀取失敗”。內(nèi)容三:設(shè)計(jì)中,把布局設(shè)置為空布局,以設(shè)置各按鈕的準(zhǔn)確位置,利用JButton、JLavel和JTextField設(shè)定界面,設(shè)定出

11、黃金卡圖形界面的布局等因素,以此滿足程序的基本設(shè)計(jì)要求。內(nèi)容四:Help.show()啟動(dòng)程序輸入文字新建打開保存關(guān)閉剪切復(fù)制粘貼制作人信息NewEditopenFileSaveListener eActionListenerCutActionCopyAction nPasteAction退出關(guān)閉程序內(nèi)容五:在窗體構(gòu)造函數(shù)BounceFrame()對(duì)窗體進(jìn)行初始化,單機(jī)start 按鈕,就馬上調(diào)用創(chuàng)建小球,啟動(dòng)線程的方法addBall(),當(dāng)小球運(yùn)動(dòng)到邊界的時(shí)候要反彈,并重畫面板。單機(jī)Close 按鈕則退出程序。2程序代碼內(nèi)容一:import java.awt.*;import java.aw

12、t.event.*;class This_number_too_big extends Exception /自定義的一個(gè)結(jié)果溢出異常類class Jsq2011 extends Frame implements ItemListener,ActionListenerpublic Jsq2011()addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)dispose();System.exit(0););static Jsq2011 mainFrame = new Jsq2011();stati

13、c Label lab=new Label("0");/創(chuàng)建標(biāo)簽static Panel pnl1=new Panel(new GridLayout(4,3,3,3);/網(wǎng)格布局static Panel pnl2=new Panel(new GridLayout(4,1,3,3);static Panel pnl3=new Panel(new GridLayout(1,2,3,3);static Panel pnl4=new Panel(new GridLayout(6,1,3,3);static Button bt9=new Button("9");s

14、tatic Button bt8=new Button("8");static Button bt7=new Button("7");static Button bt6=new Button("6");static Button bt5=new Button("5");static Button bt4=new Button("4");static Button bt3=new Button("3");static Button bt2=new Button("2&

15、quot;);static Button bt1=new Button("1");static Button bt0=new Button("0");static Button btdot=new Button(".");static Button btequ=new Button("=");static Button btadd=new Button("+");static Button btsub=new Button("-");static Button btmul=n

16、ew Button("*");static Button btdev=new Button("/");static Button btA=new Button("A");static Button btB=new Button("B");static Button btC=new Button("C");static Button btD=new Button("D");static Button btE=new Button("E");static Bu

17、tton btF=new Button("F");static Checkbox ckb8=new Checkbox("八進(jìn)制");/創(chuàng)建八進(jìn)制選擇框static Checkbox ckb10=new Checkbox("十進(jìn)制");static Checkbox ckb16=new Checkbox("十六進(jìn)制");static Button btc=new Button("clear");static Button btt=new Button("backspace");

18、public int number=0,length=18;/* number是用來記錄輸入的數(shù)字個(gè)數(shù), *length是用來設(shè)置在不同進(jìn)制下允許輸入的最多數(shù)字位數(shù),默認(rèn)為十進(jìn)制 */public char mark='n' /*設(shè)置運(yùn)算符號(hào)為沒有即為'n',它的值是'+''-''*''/' */public double data=0; /*設(shè)置運(yùn)算數(shù)據(jù)為零 */public char ch; /*用來臨時(shí)存放所按按鈕的第一個(gè)字符 */public boolean Refresh=false;/*

19、設(shè)置lab是否要在輸入數(shù)據(jù)的時(shí)候刷新,初始為否 */public static void main(String args)System.out.println("Starting Jsq2011.");lab.setAlignment(Label.RIGHT);/標(biāo)簽上名稱右對(duì)齊lab.setBackground(Color.white);lab.setForeground(Color.BLUE);lab.setFont(new Font("Serief",Font.BOLD,20);lab.setBounds(20,33,330,40);mainFr

20、ame.add(lab);btadd.setForeground(Color.red);btsub.setForeground(Color.red);btmul.setForeground(Color.red);btdev.setForeground(Color.red);btA.setForeground(Color.blue);btB.setForeground(Color.blue);btC.setForeground(Color.blue);btD.setForeground(Color.blue);btE.setForeground(Color.blue);btF.setForegr

21、ound(Color.blue);btc.setBackground(Color.red);btt.setBackground(Color.red);bt0.setBackground(new Color(200, 250, 200);bt1.setBackground(new Color(200, 250, 200);bt2.setBackground(new Color(200, 250, 200);bt3.setBackground(new Color(200, 250, 200);bt4.setBackground(new Color(200, 250, 200);bt5.setBac

22、kground(new Color(200, 250, 200);bt6.setBackground(new Color(200, 250, 200);bt7.setBackground(new Color(200, 250, 200);bt8.setBackground(new Color(200, 250, 200);bt9.setBackground(new Color(200, 250, 200);btdot.setBackground(new Color(200, 250, 200);btequ.setBackground(new Color(200, 250, 200);btadd

23、.setBackground(new Color(200, 250, 200);btmul.setBackground(new Color(200, 250, 200);btdev.setBackground(new Color(200, 250, 200);btsub.setBackground(new Color(200, 250, 200);btA.setBackground(new Color(200, 250, 200);btB.setBackground(new Color(200, 250, 200);btC.setBackground(new Color(200, 250, 2

24、00);btD.setBackground(new Color(200, 250, 200);btE.setBackground(new Color(200, 250, 200);btF.setBackground(new Color(200, 250, 200);CheckboxGroup grp=new CheckboxGroup();ckb8.setCheckboxGroup(grp);ckb10.setCheckboxGroup(grp);ckb16.setCheckboxGroup(grp);ckb8.setBounds(30,75,80,25);ckb10.setBounds(14

25、0,75,80,25);ckb16.setBounds(250,75,80,25);ckb8.setState(false);ckb10.setState(true);/設(shè)置初始狀態(tài)為選中十進(jìn)制ckb16.setState(false);mainFrame.add(ckb8);mainFrame.add(ckb10);mainFrame.add(ckb16);pnl1.setBounds(90,160,180,160);pnl2.setBounds(280,160,70,160);pnl3.setBounds(90,110,260,40);pnl4.setBounds(20,110,60,21

26、0);pnl1.add(bt7);pnl1.add(bt8);pnl1.add(bt9);pnl1.add(bt4);pnl1.add(bt5);pnl1.add(bt6);pnl1.add(bt1);pnl1.add(bt2);pnl1.add(bt3);pnl1.add(bt0);pnl1.add(btdot);pnl1.add(btequ);pnl2.add(btadd);pnl2.add(btsub);pnl2.add(btmul);pnl2.add(btdev);pnl3.add(btt);pnl3.add(btc);pnl4.add(btA);pnl4.add(btB);pnl4.

27、add(btC);pnl4.add(btD);pnl4.add(btE);pnl4.add(btF);btA.enable(false);btB.enable(false);btC.enable(false);btD.enable(false);btE.enable(false);btF.enable(false);mainFrame.add(pnl1);mainFrame.add(pnl2);mainFrame.add(pnl3);mainFrame.add(pnl4);mainFrame.setResizable(false);mainFrame.setLayout(null);/main

28、Frame.setSize(375,340 );mainFrame.setBounds(100,100,370,340);mainFrame.setBackground(Color.LIGHT_GRAY);mainFrame.setTitle("計(jì)算器");mainFrame.setVisible(true);ckb8.addItemListener(mainFrame);ckb10.addItemListener(mainFrame);ckb16.addItemListener(mainFrame);/* 把事件監(jiān)聽者向各個(gè)組鍵注冊(cè) */bt1.addActionList

29、ener(mainFrame);bt2.addActionListener(mainFrame);bt3.addActionListener(mainFrame);bt4.addActionListener(mainFrame);bt5.addActionListener(mainFrame);bt6.addActionListener(mainFrame);bt7.addActionListener(mainFrame);bt8.addActionListener(mainFrame);bt9.addActionListener(mainFrame);bt0.addActionListene

30、r(mainFrame);btadd.addActionListener(mainFrame);btsub.addActionListener(mainFrame);btmul.addActionListener(mainFrame);btdev.addActionListener(mainFrame);btt.addActionListener(mainFrame);btc.addActionListener(mainFrame);btdot.addActionListener(mainFrame);btequ.addActionListener(mainFrame);btA.addActi

31、onListener(mainFrame);btB.addActionListener(mainFrame);btC.addActionListener(mainFrame);btD.addActionListener(mainFrame);btE.addActionListener(mainFrame);btF.addActionListener(mainFrame);/* end main() mothed */*/* checkbox 事件的處理 */*/public void itemStateChanged(ItemEvent e)mark='n'Refresh=fa

32、lse; /* 規(guī)定當(dāng)進(jìn)制轉(zhuǎn)換時(shí)以前輸入的運(yùn)算符失效 */if (ckb8.getState()=true) /*八進(jìn)制選擇框處于選中狀態(tài)*/btA.enable(false); /*在八進(jìn)制的情況下對(duì)有些按件的管理 */btB.enable(false);btC.enable(false);btD.enable(false);btE.enable(false);btF.enable(false);bt9.enable(false);bt8.enable(false);btdot.enable(false);btadd.enable(false);btmul.enable(false);bts

33、ub.enable(false);btdev.enable(false);btequ.enable(false);if(length=18) /即上次選擇的是十進(jìn)制lab.setText(goto10_8(lab.getText();number=lab.getText().length();if(length=14) /上次選擇的是十六進(jìn)制lab.setText(goto_10(lab.getText(),16L);lab.setText(goto10_8(lab.getText();number=lab.getText().length();length=19; /*在八進(jìn)制下允許輸入數(shù)字

34、個(gè)數(shù)最多為19位 */if(ckb10.getState()=true) /十進(jìn)制btA.enable(false); /* 在十進(jìn)制的情況下對(duì)有些按件的管理 */btB.enable(false);btC.enable(false);btD.enable(false);btE.enable(false);btF.enable(false);bt9.enable(true);bt8.enable(true);btdot.enable(true);btadd.enable(true);btmul.enable(true);btsub.enable(true);btdev.enable(true)

35、;btequ.enable(true);if(length=19)lab.setText(goto_10(lab.getText(),8L);number=lab.getText().length();if(length=14)lab.setText(goto_10(lab.getText(),16L); /*進(jìn)制轉(zhuǎn)換成十進(jìn)制*/number=lab.getText().length();length=18; /*在十進(jìn)制下允許輸入數(shù)字個(gè)數(shù)最多為18位*/if(ckb16.getState()=true) /十六進(jìn)制btA.enable(true); /*在十六進(jìn)制的情況下對(duì)有些按件的管理*/

36、btB.enable(true);btC.enable(true);btD.enable(true);btE.enable(true);btF.enable(true);bt9.enable(true);bt8.enable(true);btdot.enable(false);btadd.enable(false);btmul.enable(false);btsub.enable(false);btdev.enable(false);btequ.enable(false);if(length=18)lab.setText(goto10_16(lab.getText();number=lab.g

37、etText().length();if(length=19)lab.setText(goto_10(lab.getText(),8L);lab.setText(goto10_16(lab.getText();number=lab.getText().length();/將其他進(jìn)制轉(zhuǎn)換成十六進(jìn)制length=14; /在十六進(jìn)制下允許輸入數(shù)字個(gè)數(shù)最多為14位/end itemStateChanged(ItemEvent e) method/*/* 按鈕事件的處理 */*/public void actionPerformed(ActionEvent m)Button btn=(Button)

38、m.getSource();etLabel().charAt(0);Object temp=m.getSource();switch (ch)case 'c': lab.setText("0"); number=0; mark='n' Refresh=false;break;/初始化case '1': enter(); break;case '2': enter(); break;case '3': enter(); break;case '4': enter(); break;

39、case '5': enter(); break;case '6': enter(); break;case '7': enter(); break;case '8': enter(); break;case '9': enter(); break;case '0':if(Refresh=true)lab.setText("0"); number=0; Refresh=false;if(lab.getText().charAt(0)='0'&& l

40、ab.getText().length()=1)break;if(number<length)number+;lab.setText(lab.getText()+ch);else break;break;case 'A': enter(); break;case 'B': enter(); break;case 'C': enter(); break;case 'D': enter(); break;case 'E': enter(); break;case 'F': enter(); bre

41、ak;case '.':if(Refresh=true)lab.setText("0"); number=0; Refresh=false;if(lab.getText().indexOf('.')= -1)number+;lab.setText(lab.getText()+ch);else break; break;case 'b':if(number=0) break;elseif(-number=0)lab.setText("0"); number=0;elseif (number!=1)lab.se

42、tText(lab.getText().substring(0,number);elselab.setText(Character.toString(lab.getText().charAt(0);break;case '+': try js();catch(This_number_too_big e)lab.setText("0"); number=0; mark='n'Refresh=false; System.out.println("The number is too big");/*如果出現(xiàn)異常則初始化效果如同c

43、lear鍵 */ break;case '-': try js();catch(This_number_too_big e)lab.setText("0"); number=0; mark='n'Refresh=false; System.out.println("The number is too big"); break;case '*': try js();catch(This_number_too_big e)lab.setText("0"); number=0; mark=&#

44、39;n'Refresh=false; System.out.println("The number is too big"); break;case '/': try js();catch(This_number_too_big e)lab.setText("0"); number=0; mark='n'Refresh=false; System.out.println("The number is too big"); break;case '=': try js();cat

45、ch(This_number_too_big e)lab.setText("0"); number=0; mark='n'Refresh=false; System.out.println("The number is too big"); break;/end actionPerformed(ActionEvent e) method/*/* 八進(jìn)制或十六進(jìn)制轉(zhuǎn)換成十進(jìn)制I */*/public String goto_10(String s,long l)/* 參數(shù)s: 是要轉(zhuǎn)換的字符串,由于輸入的控制,保證了字符串的合法性;*/ /

46、* 參數(shù)l: 使用來設(shè)置是將8進(jìn)制還是16進(jìn)制轉(zhuǎn)換成10進(jìn)制,它的有效值為8或16 */String str=s; /用來轉(zhuǎn)換的字符串long j=l; /表示進(jìn)制long lg=0,jing=1;/lg用來記錄權(quán)乘和,jing用來記錄位權(quán)char cha;/臨時(shí)記錄要轉(zhuǎn)換的字符for(int i=1;i<=str.length();i+) cha=str.charAt(str.length()-i);switch(cha)case '1': lg=lg+1*jing;break;case '2': lg=lg+2*jing;break;case '

47、;3': lg=lg+3*jing;break;case '4': lg=lg+4*jing;break;case '5': lg=lg+5*jing;break;case '6': lg=lg+6*jing;break;case '7': lg=lg+7*jing;break;case '8': lg=lg+8*jing;break;case '9': lg=lg+9*jing;break;case 'A': lg=lg+10*jing;break;case 'B&

48、#39;: lg=lg+11*jing;break;case 'C': lg=lg+12*jing;break;case 'D': lg=lg+13*jing;break;case 'E': lg=lg+14*jing;break;case 'F': lg=lg+15*jing;break;jing*=j; /位權(quán)升一級(jí),為下次使用做好準(zhǔn)備return Long.toString(lg);/end String goto_10() method/*/* 十進(jìn)制轉(zhuǎn)換成十六進(jìn)制 */*/public String goto10_16(

49、String s)/* 參數(shù)s: 是要轉(zhuǎn)換的字符串,由于輸入的控制,保證了字符串的合法性;*/String str=s; /用來轉(zhuǎn)換的字符串String st=new String();/用來記錄16進(jìn)制值的字符串long ch; /每次取余有的值int k; /將每次取余有的值轉(zhuǎn)換成整形,用來選擇轉(zhuǎn)換的16進(jìn)制字符long lg;/用來轉(zhuǎn)換的10進(jìn)制數(shù)if(str.charAt(0)='-') /如果有負(fù)號(hào)則出去負(fù)號(hào)str=str.substring(1,str.length()-1);if(str.indexOf('E')!= -1)/如果是科學(xué)計(jì)數(shù)值則出去

50、小數(shù)點(diǎn)和E后面的數(shù)str=str.charAt(0)+str.substring(2,str.indexOf('E');if (str.indexOf('.')!= -1)/如果有小數(shù)點(diǎn)則出去小數(shù)點(diǎn)及小數(shù)點(diǎn)后面的內(nèi)容str=str.substring(0,str.indexOf('.');lg=Long.parseLong(str);/將簡化的字符串轉(zhuǎn)化為長整形給lgwhile (lg>=16)ch=lg%16;k=(int)ch;switch (k)case 10: st="A"+st;break;case 11: s

51、t="B"+st;break;case 12: st="C"+st;break;case 13: st="D"+st;break;case 14: st="E"+st;break;case 15: st="F"+st;break;default: st=Long.toString(ch)+st;lg=lg/16;k=(int)lg;switch (k)case 10: st="A"+st;break;case 11: st="B"+st;break;cas

52、e 12: st="C"+st;break;case 13: st="D"+st;break;case 14: st="E"+st;break;case 15: st="F"+st;break;default: st=Long.toString(lg)+st;return st;/end goto10_16() method/*/* 十進(jìn)制轉(zhuǎn)換成八進(jìn)制 */*/public String goto10_8(String s)String str=s;String st=new String();long j=8,c

53、h;long lg;if(str.charAt(0)='-') /如果有負(fù)號(hào)則出去負(fù)號(hào)h()-1);if(str.indexOf('E')!= -1)/如果是科學(xué)計(jì)數(shù)值則出去小數(shù)點(diǎn)和E后面的數(shù)str=str.charAt(0)+str.substring(2,str.indexOf('E');if (str.indexOf('.')!= -1)/如果有小數(shù)點(diǎn)則出去小數(shù)點(diǎn)及小數(shù)點(diǎn)后面的內(nèi)容str=str.substring(0,str.indexOf('.');lg=Long.parseLong(str);while (lg>=j)ch=lg%j;st=Long.toString(ch)+st;lg=lg/j;st=Long.toString(lg)+st;return st;/end goto10_8() method/*/* 輸入字符 */*/public void enter()if(Refresh=true)/* 如果已經(jīng)設(shè)置了 運(yùn)算符則在下一次輸入數(shù)據(jù)的時(shí)候要把以前l(fā)ab的內(nèi)容清除掉 */

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論