第一篇:java課程設(shè)計(jì)報(bào)告—計(jì)算器
1--計(jì)算器 Java實(shí)習(xí)報(bào)告
目錄
一、課程設(shè)計(jì)目的.................................................................................................................2
二、課程設(shè)計(jì)任務(wù)..................................................................................................................2
2.1、設(shè)計(jì)任務(wù)................................................................................................................2
2.2、課程設(shè)計(jì)要求:....................................................................................................2
2.3、需求分析................................................................................................................2
三、開發(fā)工具與平臺.............................................................................................................3
3.1、開發(fā)工具................................................................................................................3
3.2、開發(fā)平臺................................................................................................................3
四、設(shè)計(jì)思路..........................................................................................................................4
4.1、界面設(shè)計(jì).................................................................................................................4
4.2.1、邏輯設(shè)計(jì).............................................................................................................4
4.2.2、程序流程圖...........................................................................................................5
4.2.3、主要代碼展示及說明............................................................................................5
4.3、程序測試............................................................................................................10
五、實(shí)驗(yàn)小結(jié)........................................................................................................................11
六、附錄(程序代碼)..........................................................................................................12
頁
第 1--計(jì)算器 Java實(shí)習(xí)報(bào)告
一、課程設(shè)計(jì)目的
1、熟練掌握java面向?qū)ο缶幊獭?/p>
2、選擇合適的數(shù)據(jù)結(jié)構(gòu)實(shí)現(xiàn)需求。
3、熟練使用各種控制結(jié)構(gòu)。
4、GUI組件、事件處理技術(shù)。
二、課程設(shè)計(jì)任務(wù)
2.1、設(shè)計(jì)任務(wù)
設(shè)計(jì)一個簡易的計(jì)算器,可以進(jìn)行四則運(yùn)算:加、減、乘、除等(限于十進(jìn)制下)
程序要求:
(1)應(yīng)具有相應(yīng)的界面,可參考Windows操作系統(tǒng)自帶的計(jì)算器界面。(2)操作符號定為:“+”,“-”,“*”,“/”,“+/-”等。(按國際慣例設(shè)計(jì))(3)用戶通過點(diǎn)擊程序界面上按鈕,實(shí)現(xiàn)數(shù)字、運(yùn)算符的輸入操作。(4)以上部分為必須完成的內(nèi)容。選作部分:
(1)具有操作符號“1/x”,“sqrt”(開方),“.”(小數(shù)功能)等。
2.2、課程設(shè)計(jì)要求:
(1)應(yīng)用自己所學(xué)課程知識完成對計(jì)算器的基本任務(wù)。
(2)查閱相關(guān)資料,學(xué)習(xí)和掌握項(xiàng)目中涉及的新知識,提高自學(xué)能力。
(3)通過應(yīng)用java程序編寫計(jì)算器來提升自己對簡單的圖形界面有一定的掌握和了解。
2.3、需求分析
1.設(shè)計(jì)的計(jì)算器可以完成加法、減法、乘法、除法的簡單運(yùn)算。2.實(shí)現(xiàn)一些簡單的擴(kuò)展運(yùn)算,如:正負(fù)號、倒數(shù)、退格、清零等功能。
頁
第 2--計(jì)算器 Java實(shí)習(xí)報(bào)告3.添加小數(shù)點(diǎn)功能,用以實(shí)現(xiàn)浮點(diǎn)型數(shù)據(jù)的計(jì)算。
4.使用布局管理器設(shè)計(jì)一個計(jì)算器的界面,使用事件監(jiān)聽器處理數(shù)據(jù)的輸入,并完成相關(guān)的計(jì)算。
三、開發(fā)工具與平臺
3.1、開發(fā)工具
Microsoft Windows 7旗艦版
3.2、開發(fā)平臺
JDK1.6.0-02 和UE編譯器
頁
第 3--計(jì)算器 Java實(shí)習(xí)報(bào)告
四、設(shè)計(jì)思路
4.1、界面設(shè)計(jì):(如圖3-1)
圖3-1
4.2.1、邏輯設(shè)計(jì):
(1)根據(jù)所設(shè)計(jì)出來的界面,首先要設(shè)計(jì)其GUI界面,總體界面有一個文本框,20個按鈕,總體界面用BorderLayout布局,文本框放置在最NORTH,然后0到9以及+,-,*,/等按鈕放置到一個面板Panel中,完成界面設(shè)計(jì)。
(2)設(shè)計(jì)計(jì)算流程,首先點(diǎn)擊數(shù)字按鈕時(shí),將按鈕數(shù)值添加到文本框當(dāng)中,并將該數(shù)值保存到一個字符串中,再次點(diǎn)擊數(shù)字按鈕時(shí),將之前保存的字符串與新的數(shù)值拼接起來,再添加到文本框當(dāng)中,直到點(diǎn)擊運(yùn)算符按鈕時(shí),將文本框當(dāng)中的字符串保存在一個字符串變量中,然后重置文本框內(nèi)容,將運(yùn)算符號顯示到文本框中,隨后輸入第二個計(jì)算數(shù)據(jù)時(shí),用同樣的辦法保存數(shù)據(jù),最后通過控制“=”運(yùn)算符先將字符串?dāng)?shù)據(jù)轉(zhuǎn)化成雙精度類型,然后計(jì)算出結(jié)果并顯示到文本框當(dāng)中。
(3)基本運(yùn)算設(shè)計(jì)完成以后則開始考慮其他個別功能的實(shí)現(xiàn),例如倒數(shù)、清零、退格等功能的實(shí)現(xiàn),清零直接重置文本框內(nèi)容,退格功能則采用substring函數(shù)截取字符串長度。
頁
第 4--計(jì)算器 Java實(shí)習(xí)報(bào)告
4.2.2、程序流程圖:
4.2.3、主要代碼展示及說明: 總體代碼的設(shè)計(jì):
程序采用繼承windowadapter類,新建Jframe窗體,利用數(shù)組來定義JBotton按鈕,同時(shí)利用數(shù)組注冊監(jiān)聽,采用4行5列網(wǎng)格布局,完成計(jì)算器界面的基本設(shè)置,在窗體的正常關(guān)閉方面,采用匿名類實(shí)現(xiàn)窗體的正常關(guān)閉。最后對按鈕進(jìn)行計(jì)算分析,分別設(shè)定輸入數(shù)據(jù)的A類、運(yùn)算符控制的Opertion類,退格功能的BackSpace類、計(jì)算結(jié)果的Result類等等,一步步實(shí)現(xiàn)計(jì)算器的基本功能!
(1)類A的設(shè)計(jì)(數(shù)據(jù)的輸入)
class A implements ActionListener { public void actionPerformed(ActionEvent e){
String a = Jtext.getText();
String s = e.getActionCommand();
if(a.equals(“0.”)||a.equals(“+”)||a.equals(“-”)||a.equals(“*”)||a.equals(“/”))
頁
第 5--計(jì)算器 Java實(shí)習(xí)報(bào)告
}
} Jtext.setText(s);else { if(flag2){
Jtext.setText(s);
flag2=false;} else
Jtext.setText(a+s);}
功能解釋:程序開始時(shí),程序初始化文本框的內(nèi)容為“0.”,點(diǎn)擊數(shù)字按鈕,則調(diào)用類A,首先用a來獲取當(dāng)前文本框內(nèi)容,s來獲取按鈕數(shù)值,然后進(jìn)行判斷,若a的值為上述代碼的值則輸出s的值,再次點(diǎn)擊數(shù)字按鈕時(shí),再次調(diào)用A類,此時(shí)a的值為上次輸入的s值,第一個if語句不滿足,執(zhí)行下個if語句if(flag2),flag2初始值為false,該語句的功能是在執(zhí)行了“=”號按鈕時(shí),防止新的數(shù)字按鈕的值合并到到已經(jīng)得出的結(jié)果上,例如:12+12=24,此時(shí)再點(diǎn)擊數(shù)字按鈕3時(shí),則文本框內(nèi)容被重置,輸出數(shù)值3,而不是243,如果if(flag2)不滿足,則將字符串a(chǎn)和s合并并輸出,得出第一個要計(jì)算的數(shù)據(jù)。
(2)類Opertion的設(shè)計(jì):(運(yùn)算符的控制)
class Opertion implements ActionListener { public void actionPerformed(ActionEvent e){
cal=e.getActionCommand();
if(flag1==true)
x=Jtext.getText();
Jtext.setText(cal);
flag1=false;}
頁
第 6--計(jì)算器 Java實(shí)習(xí)報(bào)告 }
功能解釋:當(dāng)點(diǎn)擊運(yùn)算符控制按鈕時(shí),首先將運(yùn)算符的數(shù)值賦值給cal(初值為空),緊接著進(jìn)行判斷,flag1初值為ture,該類的作用為在點(diǎn)擊運(yùn)算符按鈕時(shí),將計(jì)算的第一個數(shù)據(jù)保存在x字符串變量當(dāng)中,然后將文本框內(nèi)容重置為點(diǎn)擊的運(yùn)算符的數(shù)值,類的結(jié)尾將flag1賦值為false,防止再次點(diǎn)擊運(yùn)算符按鈕時(shí)改變了x的值。
(附:此時(shí)文本框內(nèi)容為運(yùn)算符的值,輸入第二個計(jì)算數(shù)據(jù)時(shí),點(diǎn)擊數(shù)字按鈕,則再次調(diào)用A類,此時(shí)滿足A類中第一個if語句,文本框內(nèi)容被重置為數(shù)字按鈕的值,接下來與獲取第一個計(jì)算數(shù)據(jù)步驟一樣,直到點(diǎn)擊“=”號運(yùn)算符為止?。?/p>
(3)類Result的設(shè)計(jì):(計(jì)算并輸出結(jié)果)
class Result implements ActionListener //計(jì)算并顯示結(jié)果 { public void actionPerformed(ActionEvent e){
double num1;
num1=Double.parseDouble(x);
y=Jtext.getText();
double num2;
num2=Double.parseDouble(y);
double result=0;
if(num2!=0)
{
if(cal.equals(“+”))
result=num1+num2;
if(cal.equals(“-”))
result=num1-num2;
if(cal.equals(“*”))
result=num1*num2;
String s1=Double.toString(result);
Jtext.setText(s1);
}
if(cal.equals(“/”))
頁
第 7--計(jì)算器 Java實(shí)習(xí)報(bào)告
} {
if(num2==0)
Jtext.setText(“除數(shù)不能為0”);
else
{
result=num1/num2;
String s1=Double.toString(result);
Jtext.setText(s1);
} }
flag1=true;
flag2=true;} 功能解釋:首先定義兩個Double型num1,num2,將之前保存的第一個計(jì)算數(shù)據(jù)x強(qiáng)制轉(zhuǎn)換為Double型后賦值給num1,接著用字符串變量y來獲取當(dāng)前文本框的內(nèi)容,即第二個計(jì)算數(shù)據(jù)的值,同樣再將其強(qiáng)制轉(zhuǎn)換Double型后賦值給num2,然后進(jìn)行運(yùn)算符判斷,對cal的值進(jìn)行比較,然后進(jìn)行相應(yīng)的計(jì)算,將計(jì)算的結(jié)果轉(zhuǎn)換成字符串后將其輸出到文本框中,在類的最后將flag1、flag2賦值為true,作用是將計(jì)算的結(jié)果當(dāng)作第二次計(jì)算的數(shù)據(jù)進(jìn)行再運(yùn)算,即將結(jié)果重新賦值給x作為第一個計(jì)算數(shù)據(jù)!(附:在此類中還考慮了當(dāng)除數(shù)為零的情況。)
(4)類BackSpace的設(shè)計(jì):(功能類—退格)
class BackSpace implements ActionListener { public void actionPerformed(ActionEvent e){
String s = e.getActionCommand();
String s1 = Jtext.getText();
if(s.equals(“退格”))
s1=new String(s1.substring(0,s1.length()-1));
Jtext.setText(s1);} }
頁
第 8--計(jì)算器 Java實(shí)習(xí)報(bào)告
功能解釋:這是計(jì)算器附加功能的實(shí)現(xiàn),這里只介紹退格功能,像正負(fù)號、求倒數(shù)、清零等功能相似,所以就不再一一介紹。首先獲取退格按鈕的命令值賦給s,然后獲取當(dāng)前文本框的內(nèi)容,即輸入的數(shù)據(jù),將其賦給s1,接著進(jìn)行判斷,利用substring函數(shù)將s1字符串截取為從第一個字符至倒數(shù)第二個字符為止的字符串并重新賦值給s1,再將其輸出到文本框,實(shí)現(xiàn)退格的功能。
第 9
頁 10--計(jì)算器 Java實(shí)習(xí)報(bào)告
4.3、程序測試
1.簡單的運(yùn)算:(以加法為例:123+456)
分析:計(jì)算的結(jié)果為579.0,為雙精度型,計(jì)算的結(jié)果被設(shè)置在文本框的最右端,該計(jì)算器的一個特點(diǎn)是可直接在文本框中輸入數(shù)據(jù)以及進(jìn)行更改。
2.倒數(shù)的運(yùn)算:(以123為例)
分析:輸出的結(jié)果如圖所示,倒數(shù)功能實(shí)現(xiàn),計(jì)算時(shí),不僅是結(jié)果,輸入的數(shù)據(jù)同樣可以先實(shí)現(xiàn)倒數(shù)功能后再進(jìn)行相應(yīng)的計(jì)算,沒有影響!
3.退格的運(yùn)算:(以123為例)
分析:輸出的結(jié)果如圖所示,本計(jì)算器退格鍵有一個特點(diǎn)是,就算是是計(jì)算后得出的結(jié)果也能實(shí)現(xiàn)退格,缺點(diǎn)是不能很好的處理小數(shù)點(diǎn)的問題,因?yàn)樾?shù)點(diǎn)也是字符串的一部分。
頁
第 10--計(jì)算器 Java實(shí)習(xí)報(bào)告
4.正負(fù)號的運(yùn)算:(以123為例)
分析:輸出的結(jié)果如圖所示,正負(fù)號添加能夠很好的實(shí)現(xiàn),但可以進(jìn)行一些改進(jìn),比如在計(jì)算過程當(dāng)中直接點(diǎn)擊負(fù)號運(yùn)算符輸入負(fù)數(shù)進(jìn)行計(jì)算!
5.總體分析:
該計(jì)算器基本運(yùn)算沒有問題,清零、正負(fù)號、求倒數(shù)、退格功能都能很好的實(shí)現(xiàn),總體能完成一個計(jì)算器的基本功能,但仍有許多地方需要改進(jìn),比如小數(shù)點(diǎn)的實(shí)現(xiàn)所存在的一些問題,雖然在基本的運(yùn)算過程當(dāng)中不會造成太大影響,但這依然不能認(rèn)為是一個很好的計(jì)算器,同時(shí),在另一方面,該計(jì)算器還沒能很好的實(shí)現(xiàn)連續(xù)計(jì)算的功能,必須每次按下等號按鈕計(jì)算出結(jié)果后才能用產(chǎn)生的結(jié)果接著進(jìn)行下一次的計(jì)算,改進(jìn)的方法是在運(yùn)算符上同時(shí)注冊Result類,讓運(yùn)算符同時(shí)擁有計(jì)算結(jié)果的功能。
五、實(shí)驗(yàn)小結(jié)
本次課程設(shè)計(jì)到此算是告一段落了,經(jīng)過這次的學(xué)習(xí),我學(xué)到了很多東西,在此基礎(chǔ)上更加鞏固了自己對java的認(rèn)識與了解。
在做本項(xiàng)目是時(shí)候,會遇到很多小問題,比如說,在整個運(yùn)算過程中要如何確保輸入的計(jì)算數(shù)據(jù)哪個是第一個計(jì)算數(shù)據(jù)的,哪個是第二個計(jì)算
頁
第 11--計(jì)算器 Java實(shí)習(xí)報(bào)告數(shù)據(jù)的,同時(shí)也要區(qū)分運(yùn)算符,因?yàn)樵撚?jì)算器程序應(yīng)用的都是利用字符串來完成計(jì)算的,而且不能重復(fù)輸出運(yùn)算符,更不能將運(yùn)算符錯誤的存儲在了第一個計(jì)算數(shù)據(jù)的數(shù)值中,也得考慮到萬一不小心重復(fù)點(diǎn)擊了運(yùn)算符按鈕會不會造成第一個計(jì)算數(shù)據(jù)的重新賦值等等問題,最后想到利用布爾類型來很好的控制運(yùn)算符的應(yīng)用!
此次課程設(shè)計(jì)讓我更了解熟悉了Java中的圖形用戶界面和它的編程方式。在完成課題的過程中也不斷充實(shí)了自己,學(xué)習(xí)到了很多以前沒有學(xué)習(xí)到的知識,收獲很大。最大的收獲就是對大學(xué)學(xué)習(xí)的總結(jié)和培養(yǎng)了解決困難的信心和能力,使我對所學(xué)知識能夠融會貫通,又不斷豐富了新知識。Java計(jì)算器設(shè)計(jì)使得我們對所學(xué)的專業(yè)課有了更為深刻的認(rèn)識,使得知識得到了鞏固和提高。
在接下來的時(shí)間里,我覺得我要更加努力的往深一層次的方面看齊,了解更多有關(guān)java的知識,對java有更深一步的了解,我會一步一步的走下去!
六、附錄(程序代碼)import java.awt.*;import javax.swing.*;import java.awt.event.*;
public class TheCalculator extends WindowAdapter
//程序框架繼承自WindowAdapter類 { private JTextField Jtext=new JTextField(“0.”);private JFrame f=new JFrame(“計(jì)算器-趙磊”);private String x=“";private String y=”“;private String cal=”“;private boolean flag1=true;private boolean flag2=false;
public void init()//初始化
{
String[] buttonValue = new String[]{”1“,”2“,”3“,”+“,”C“,”4“,”5“,”6“,”-“,”退格
頁
第 12--計(jì)算器 Java實(shí)習(xí)報(bào)告“,”7“,”8“,”9“,”*“,”1/x“,”0“,”+/-“,”.“,”/“,”=“};
Container contain = f.getContentPane();
JPanel Jpan = new JPanel();
JButton[] Jb=new JButton[20];
contain.setLayout(new BorderLayout());//采用4行5列的網(wǎng)格布局
Jpan.setLayout(new GridLayout(4,5));
Jtext.setHorizontalAlignment(JTextField.RIGHT);
contain.add(Jtext,”North“);
contain.add(Jpan);
A num=new A();//數(shù)據(jù)
Result re=new Result();//結(jié)果
Opertion op=new Opertion();//運(yùn)算符
Clear cl=new Clear();//清零
BackSpace back=new BackSpace();//退格
CountDown count_d=new CountDown();//倒數(shù)
Strains stra=new Strains();//相反數(shù)
for(int i = 0;i { Jb[i] = new JButton(buttonValue[i]); Jpan.add(Jb[i]); if(i==3 || i==8 || i==13 || i==18) Jb[i].addActionListener(op); if(i==0 || i==1 || i==2 || i==5 || i==6 || i==7|| i==10 || i==11 || i==12 || i==15 || i==17) Jb[i].addActionListener(num); if((i==3||i==4||i==8||i==9)||((i>12)&&(i<=19))&&i!=15) Jb[i].setForeground(new Color(255, 0, 0)); else Jb[i].setForeground(new Color(0, 0, 255));//控制按鈕字體顏色 } Jb[4].addActionListener(cl); Jb[9].addActionListener(back); Jb[14].addActionListener(count_d); Jb[16].addActionListener(stra); Jb[19].addActionListener(re); f.setSize(320,240); f.setVisible(true); f.addWindowListener(//采用匿名類實(shí)現(xiàn)窗口的正常關(guān)閉 new WindowAdapter() 頁 第 13--計(jì)算器 Java實(shí)習(xí)報(bào)告 { public void windowClosing(WindowEvent e) { System.exit(0); } });} class A implements ActionListener //輸入數(shù)據(jù) { public void actionPerformed(ActionEvent e){ String a = Jtext.getText(); String s = e.getActionCommand(); if(a.equals(”0.“)||a.equals(”+“)||a.equals(”-“)||a.equals(”*“)||a.equals(”/“)) Jtext.setText(s); else { if(flag2) { Jtext.setText(s); flag2=false; } else Jtext.setText(a+s); } } } class Opertion implements ActionListener { public void actionPerformed(ActionEvent e){ cal=e.getActionCommand(); if(flag1==true) x=Jtext.getText(); Jtext.setText(cal); flag1=false;} } 頁 第 14--計(jì)算器 Java實(shí)習(xí)報(bào)告 class Clear implements ActionListener //清零功能 { public void actionPerformed(ActionEvent e){ Jtext.setText(”0.“);} } class CountDown implements ActionListener //求倒數(shù)類 { public void actionPerformed(ActionEvent e){ String s = e.getActionCommand(); String s1 = Jtext.getText(); if(s.equals(”1/x“)) s1 = new String(”“+1/Double.parseDouble(s1)); Jtext.setText(s1);} } class Strains implements ActionListener //求相反數(shù)類 { public void actionPerformed(ActionEvent e){ String s = e.getActionCommand(); String s1 = Jtext.getText(); if(s.equals(”+/-“)) s1=new String(”“+(0-Double.parseDouble(s1))); Jtext.setText(s1);} } class BackSpace implements ActionListener //退格功能 { public void actionPerformed(ActionEvent e){ String s = e.getActionCommand(); String s1 = Jtext.getText(); if(s.equals(”退格“)) s1=new String(s1.substring(0,s1.length()-1)); Jtext.setText(s1);} 頁 第 15--計(jì)算器 Java實(shí)習(xí)報(bào)告 } class Result implements ActionListener //計(jì)算并顯示結(jié)果 { public void actionPerformed(ActionEvent e){ double num1; num1=Double.parseDouble(x); y=Jtext.getText(); double num2; num2=Double.parseDouble(y); double result=0; if(num2!=0) { if(cal.equals(”+“)) result=num1+num2; if(cal.equals(”-“)) result=num1-num2; if(cal.equals(”*“)) result=num1*num2; String s1=Double.toString(result); Jtext.setText(s1); } if(cal.equals(”/“)) { if(num2==0) Jtext.setText(”除數(shù)不能為0"); else { result=num1/num2; String s1=Double.toString(result); Jtext.setText(s1); } } flag1=true; flag2=true;} } public static void main(String[] args)//main方法 { 頁 第 16--計(jì)算器 Java實(shí)習(xí)報(bào)告 } } TheCalculator count=new TheCalculator();count.init(); 頁 第 17 1、設(shè)計(jì)目的 運(yùn)用MATLAB實(shí)現(xiàn)MATLAB的GUI程序設(shè)計(jì)。 2、題目分析 2.1課程設(shè)計(jì)的基本要求: A.熟悉和掌握MATLAB 程序設(shè)計(jì)方法。B.掌握MATLAB GUI程序設(shè)計(jì)。2.2課程設(shè)計(jì)的內(nèi)容 要求利用MATLAB GUI設(shè)計(jì)實(shí)現(xiàn)一個圖形用戶界面的計(jì)算器程序,要求實(shí)現(xiàn): A.具有友好的用戶圖形界面。實(shí)現(xiàn)十進(jìn)制數(shù)的加、減、乘、除、乘方、取模等簡單計(jì)算。 B.科學(xué)計(jì)算函數(shù),包括(反)正弦、(反)余弦、(反)正切、(反)余切、開方、指數(shù)等函數(shù)運(yùn)行。 C.能夠保存上次歷史計(jì)算的答案,顯示答案存儲器中的內(nèi)容。D.有清除鍵,能清除操作。 E.獨(dú)立存儲器功能,使之可以直接輸入存儲器,可與存儲器中的數(shù)值相加減。能夠清除獨(dú)立存儲器中的內(nèi)容。2.3題目分析 本題目通過MATLAB的GUI程序設(shè)計(jì)較為簡單,在GUI設(shè)計(jì)中主要用到三種控件,顯示框用到文本編輯框(edit text),說明框用到靜態(tài)文本框(Static text),數(shù)字以及運(yùn)算等按鈕用到命令按鈕(push button)。然后再通過各個按鈕的回調(diào)函數(shù),實(shí)現(xiàn)簡單的計(jì)算功能。 3、總體設(shè)計(jì) 首先用MATLAB GUI功能,在繪制一個靜態(tài)文本框和一個文本編輯框,以及32個命令按鈕,調(diào)整好各控件大小、顏色,整體布局如圖所示: 然后通過雙擊個按鈕來改寫其屬性,在m文件中編寫其回調(diào)函數(shù),最后在運(yùn)行調(diào)試。 4、具體設(shè)計(jì) 4.1 各功能界面設(shè)計(jì) GUI設(shè)計(jì)界面: 4.2 各功能模塊實(shí)現(xiàn) 算法設(shè)計(jì): A.數(shù)字鍵設(shè)計(jì):0—9以及小數(shù)點(diǎn)函數(shù)都一樣,只是參數(shù)不同: global jj textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','1');else textString =strcat(textString,'1');set(handles.text1,'String',textString)end jj=0;B.四則運(yùn)算函數(shù): textString = get(handles.text1,'String');textString =strcat(textString,'+');set(handles.text1,'String',textString)C.科學(xué)計(jì)算函數(shù): textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)set(handles.text1,'String','0.');else a = strread(textString, '%f');a=sin(a);set(handles.text1,'String',a)end 或 textString=handles.text1;textString=sin(str2num(get(handles.text1,'String'))*pi/180);set(handles.text1,'String',num2str(textString))D.退格鍵:通過取屏幕值,計(jì)算出其字符長度,然后取其前N-1項(xiàng)的值來實(shí)現(xiàn)退格: global jj textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','0.');else ss=char(textString);l=length(textString);textString=ss(1:l-1);set(handles.text1,'String',textString)end jj=0;E.清屏鍵函數(shù): set(handles.text1,'String','0.');F.右鍵函數(shù): gtext('大家好;我是智能機(jī)器人-my name is seven');close(gcf);4.3 各模塊實(shí)現(xiàn)結(jié)果 A.數(shù)字鍵: B.四則運(yùn)算函數(shù): C.科學(xué)計(jì)算函數(shù): Sin45的計(jì)算結(jié)果= 經(jīng)過計(jì)算,這些結(jié)果均與實(shí)際結(jié)果相吻合,計(jì)算器的功能實(shí)現(xiàn)的較為完好。5.2問題和解決方法: a.小數(shù)點(diǎn)可以連續(xù)輸入。解決方法是:用strfind函數(shù)查看文本框里有幾個小數(shù)點(diǎn),如果已經(jīng)有一個了,再按小數(shù)點(diǎn)就保持不變。b.按過運(yùn)算符號后一個數(shù)不等于一個數(shù),比如:輸入1,按等號,會出來一個3,經(jīng)過長時(shí)間分析得知,這是由于在按運(yùn)算符號時(shí),系統(tǒng)記錄了文本框里的數(shù)但沒有清空,才會出現(xiàn)這種問題。解決方法是再申請一個不同于加減乘除的另一個符號,并將按過運(yùn)算符后記錄的數(shù)值置0。 c.按對數(shù)函數(shù)鍵時(shí),負(fù)數(shù)也能運(yùn)算,通過加入if判斷語句來判斷輸入的值是否為負(fù),若為負(fù)則輸出error.6、心得體會 通過本次的MATLAB課程設(shè)計(jì),讓我對MATLAB尤其是其GUI設(shè)計(jì)的功能有了進(jìn)一步的了解,認(rèn)識到了它功能的強(qiáng)大。在MATLAB簡單計(jì)算器的設(shè)計(jì)中,了解了關(guān)于MATLAB圖形用戶界面的部分控件的使用方法;利用MATLAB的GUI提供的很多實(shí)用的控件,方便用于設(shè)計(jì)屬于自己的圖形界面。 7、附錄(源代碼) function varargout = jisuanqi(varargin)% JISUANQI M-file for jisuanqi.fig % JISUANQI, by itself, creates a new JISUANQI or raises the existing % singleton*.% % H = JISUANQI returns the handle to a new JISUANQI or the handle to % the existing singleton*.% % JISUANQI('CALLBACK',hObject,eventData,handles,...)calls the local % function named CALLBACK in JISUANQI.M with the given input arguments.% % JISUANQI('Property','Value',...)creates a new JISUANQI or raises the % existing singleton*.Starting from the left, property value pairs are % applied to the GUI before jisuanqi_OpeningFunction gets called.An % unrecognized property name or invalid value makes property application % stop.All inputs are passed to jisuanqi_OpeningFcn via varargin.% % *See GUI Options on GUIDE's Tools menu.Choose “GUI allows only one % instance to run(singleton)”.% % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc.% Edit the above text to modify the response to help jisuanqi % Last Modified by GUIDE v2.5 04-Dec-2012 17:06:43 % Begin initialization codeDO NOT EDIT %---Executes just before jisuanqi is made visible.function jisuanqi_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)% Get default command line output from handles structure varargout{1} = handles.output; function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles emptyto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)global jj textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','1');else textString =strcat(textString,'1');set(handles.text1,'String',textString)end jj=0; %---Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)global jj textString = get(handles.text1,'String'); if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','3');else textString =strcat(textString,'3');set(handles.text1,'String',textString)end jj=0; %---Executes on button press in pushbutton13.function pushbutton13_Callback(hObject, eventdata, handles)% hObject handle to pushbutton13(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)global jj textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','-');else textString = get(handles.text1,'String');textString =strcat(textString,'-');set(handles.text1,'String',textString)end jj=0; %---Executes on button press in pushbutton21.function pushbutton21_Callback(hObject, eventdata, handles)% hObject handle to pushbutton21(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)textString = get(handles.text1,'String');%strcmp(textString,'0.')textString=handles.text1; textString=sin(str2num(get(handles.text1,'String'))*pi/180);set(handles.text1,'String',num2str(textString))%a = strread(textString, '%f')%textString=get(handles.text1,'String')%textString=strcat(textString,'sin')%set(handles.text1,'String',textString)%---Executes on button press in pushbutton23.function pushbutton23_Callback(hObject, eventdata, handles)% hObject handle to pushbutton23(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)global jj textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','4');else textString =strcat(textString,'4');set(handles.text1,'String',textString)end jj=0; %---Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject handle to pushbutton5(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)global jj textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','6');else textString =strcat(textString,'6');set(handles.text1,'String',textString)end jj=0; %---Executes on button press in pushbutton15.function pushbutton15_Callback(hObject, eventdata, handles)% hObject handle to pushbutton15(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)global jj textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','/');else textString = get(handles.text1,'String');textString =strcat(textString,'/');set(handles.text1,'String',textString)end jj=0; %---Executes on button press in pushbutton24.function pushbutton24_Callback(hObject, eventdata, handles)% hObject handle to pushbutton24(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)textString = get(handles.text1,'String');%strcmp(textString,'0.')textString=handles.text1; textString=cos(str2num(get(handles.text1,'String'))*pi/180);set(handles.text1,'String',num2str(textString))%---Executes on button press in pushbutton26.function pushbutton26_Callback(hObject, eventdata, handles)% hObject handle to pushbutton26(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)global jj textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','7');else textString =strcat(textString,'7');set(handles.text1,'String',textString)end jj=0; %---Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)global jj textString = get(handles.text1,'String'); if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','9');else textString =strcat(textString,'9');set(handles.text1,'String',textString)end jj=0; %---Executes on button press in pushbutton17.function pushbutton17_Callback(hObject, eventdata, handles)% hObject handle to pushbutton17(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)set(handles.text1,'String',')');else textString =strcat(textString,')');set(handles.text1,'String',textString)end %---Executes on button press in pushbutton27.function pushbutton27_Callback(hObject, eventdata, handles)% hObject handle to pushbutton27(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)textString = get(handles.text1,'String');%strcmp(textString,'0.')textString=handles.text1; textString=tan(str2num(get(handles.text1,'String'))*pi/180);set(handles.text1,'String',num2str(textString))%---Executes on button press in pushbutton29.function pushbutton29_Callback(hObject, eventdata, handles)% hObject handle to pushbutton29(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA) global jj textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','0.');else textString =strcat(textString,'0');set(handles.text1,'String',textString)end jj=0; %---Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)% hObject handle to pushbutton11(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)set(handles.text1,'String','0.'); %---Executes on button press in pushbutton19.function pushbutton19_Callback(hObject, eventdata, handles)% hObject handle to pushbutton19(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)textString=get(handles.text1,'String')s=eval(textString) set(handles.text1,'String',s) %---Executes on button press in pushbutton30.function pushbutton30_Callback(hObject, eventdata, handles)% hObject handle to pushbutton30(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)textString = get(handles.text1,'String');%strcmp(textString,'0.')textString=handles.text1; textString=cot(str2num(get(handles.text1,'String'))*pi/180);set(handles.text1,'String',num2str(textString))%---Executes on button press in pushbutton32.function pushbutton32_Callback(hObject, eventdata, handles)% hObject handle to pushbutton32(see GCBO)% eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)%open('1.bmp') gtext('大家好;我是智能機(jī)器人-my name is seven'); %------function J_Callback(hObject, eventdata, handles)% hObject handle to J(see GCBO) % eventdata reservedto be defined in a future version of MATLAB % handles structure with handles and user data(see GUIDATA)close(gcf); 8、參考書目: [1]《MATLAB語言及其在電子信息工程中的應(yīng)用》 王洪元主編 清華大學(xué)出版社 [2] 《MATLAB中GUI的應(yīng)用》 王洪元主編 清華大學(xué)出版社 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 機(jī)電信息工程學(xué)院 單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 完成日期:2010年5月31日 系: 專 業(yè): 班 級: 設(shè)計(jì)題目: 學(xué)生姓名: 指導(dǎo)教師: 多功能簡易計(jì)算器 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 目 錄 一、設(shè)計(jì)任務(wù)和性能指標(biāo)......................................................................2 1.1設(shè)計(jì)任務(wù)..............................................................................................................................2 1.2性能指標(biāo)..............................................................................................................................2 二.設(shè)計(jì)方案.............................................................................................2 三.系統(tǒng)硬件設(shè)計(jì).....................................................................................3 3.1單片機(jī)最小系統(tǒng)......................................................................................3 3.2鍵盤接口電路.....................................................................................................................3 3.3數(shù)碼管顯示電路.................................................................................................................4 3.4錯誤報(bào)警電路.....................................................................................................................5 四、系統(tǒng)軟件設(shè)計(jì)..................................................................................6 4.1鍵盤掃描子程序設(shè)計(jì)..........................................................................................................6 4.2移位子程序及結(jié)果計(jì)算子程序設(shè)計(jì)................................................................................10 4.3顯示子程序設(shè)計(jì)...............................................................................................................12 4.4主程序設(shè)計(jì).......................................................................................................................13 五、調(diào)試及性能分析............................................................................13 5.1調(diào)試步驟...........................................................................................................................13 5.2性能分析...........................................................................................................................14 六、心得體會........................................................................................14 參考文獻(xiàn)................................................................................................14 附錄1 系統(tǒng)硬件電路圖.......................................................................15 附錄2 程序清單.................................................................................16 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 一、設(shè)計(jì)任務(wù)和性能指標(biāo) 1.1設(shè)計(jì)任務(wù) 利用單片機(jī)及外圍接口電路(鍵盤接口和顯示接口電路)設(shè)計(jì)制作一個計(jì)算器,用LED顯示計(jì)算數(shù)值及結(jié)果。 要求用Protel 畫出系統(tǒng)的電路原理圖(要求以最少組件,實(shí)現(xiàn)系統(tǒng)設(shè)計(jì)所要求的功能),印刷電路板(要求布局合理,線路清晰),繪出程序流程圖,并給出程序清單(要求思路清晰,盡量簡潔,主程序和子程序分開,使程序有較強(qiáng)的可讀性)。1.2性能指標(biāo) 1.2.3.4.5.加法:四位加法,計(jì)算結(jié)果若超過四位則顯示計(jì)算錯誤 減法:四位減法,計(jì)算結(jié)果若小于零則顯示計(jì)算錯誤 乘法:個位數(shù)乘法 除法:整數(shù)除法 有清零功能,計(jì)算錯誤報(bào)警 二.設(shè)計(jì)方案 按照系統(tǒng)設(shè)計(jì)的功能的要求,初步確定設(shè)計(jì)系統(tǒng)由主控模塊、顯示模塊、錯誤報(bào)警模塊、鍵掃描接口電路共四個模塊組成,電路系統(tǒng)構(gòu)成框圖如圖1.1所示。主控芯片使用51系列AT89C52單片機(jī),采用高性能的靜態(tài)80C51設(shè)計(jì),由先進(jìn)工藝制造,并帶有非易失性Flash程序存儲器。它是一種高性能、低功耗的8位COMS微處理芯片,市場應(yīng)用最多。 鍵盤電路采用4*4矩陣鍵盤電路。 顯示模塊采用4枚共陽極數(shù)碼管和74ls273鎖存芯片構(gòu)成等器件構(gòu)成。 錯誤報(bào)警電路采用5V蜂鳴器。 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 三.系統(tǒng)硬件設(shè)計(jì) 3.1單片機(jī)最小系統(tǒng) 單片機(jī)最小系統(tǒng)就是支持主芯片正常工作的最小電路部分,包括主控芯片、復(fù)位電路和晶振電路。 主控芯片選取STC89C52RC芯片,因其具有良好的性能及穩(wěn)定性,價(jià)格便宜應(yīng)用方便。 晶振選取11.0592MHz,晶振旁電容選取30pF。 采用按鍵復(fù)位電路,電阻分別選取100Ω和10K,電容選取10μF。以下為單片機(jī)最小系統(tǒng)硬件電路圖。 單片機(jī)最小系統(tǒng)硬件電路 3.2鍵盤接口電路 計(jì)算器所需按鍵有: 數(shù)字鍵:’1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’,’0’ 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 功能鍵:’+’, ’-‘ , ’*’, ’/ ’ , ’ = ’, ’ C(清零)’ 共計(jì)16個按鍵,采用4*4矩陣鍵盤,鍵盤的行和列之間都有公共端相連,四行和四列的8個公共端分別接P1.0~P1.7,這樣掃描P1口就可以完成對矩陣鍵盤的掃描,通過對16個按鍵進(jìn)行編碼,從而得到鍵盤的口地址,對比P1口德掃描結(jié)果和各按鍵的地址,我們就可以得到是哪個鍵按下,從而完成鍵盤的功能。 以下為鍵盤接口電路的硬件電路圖 鍵盤接口電路 3.3數(shù)碼管顯示電路 采用4位數(shù)碼管對計(jì)算數(shù)據(jù)和結(jié)果的顯示,這里選取共陽數(shù)碼管,利用NPN三極管對數(shù)碼管進(jìn)行驅(qū)動,為了節(jié)省I/O資源,采取動態(tài)顯示的方法來顯示計(jì)算數(shù)據(jù)及結(jié)果。 利用74273鎖存器來實(shí)現(xiàn)數(shù)碼管的動態(tài)顯示,P0口輸出顯示值,P2.4為段選口,控制273鎖存器的時(shí)鐘引腳,從而得到對數(shù)碼管輸入數(shù)據(jù)的控制。 P2.0~P2.3用來作為位選端,控制哪幾位數(shù)碼管進(jìn)行顯示。 以下為數(shù)碼顯示電路的硬件電路圖 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 數(shù)碼顯示電路硬件電路圖 3.4錯誤報(bào)警電路 錯誤報(bào)警電路就是在計(jì)算結(jié)果出現(xiàn)錯誤時(shí)或輸入數(shù)據(jù)出現(xiàn)錯誤時(shí),發(fā)出聲音警報(bào),提示使用者錯誤出現(xiàn)。 這里就采用5V蜂鳴器作為報(bào)警設(shè)備,利用PNP三極管對蜂鳴器進(jìn)行驅(qū)動,有P2.5對其進(jìn)行控制,這樣在出現(xiàn)錯誤的同時(shí)用P2.5輸出低,就可以使蜂鳴器工作,完成報(bào)警任務(wù)。 以下為報(bào)警電路硬件電路圖 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 報(bào)警電路硬件電路圖 系統(tǒng)整體硬件電路圖見附錄一 四、系統(tǒng)軟件設(shè)計(jì) 4.1鍵盤掃描子程序設(shè)計(jì) 要進(jìn)行數(shù)據(jù)的計(jì)算就必須先進(jìn)行數(shù)據(jù)的輸入,也就必須確定按鍵輸入的數(shù)值是什么,這就需要對鍵盤進(jìn)行掃描,從而確定究竟是哪個鍵按下。 對于鍵盤的掃描,既可以用行掃描也可以用列掃描,這里采用行掃描的方法來完成對鍵盤的掃描。 行掃描就是逐行掃描鍵盤,看是哪一行有鍵按下,再通過返回的鍵碼來確定究竟是哪個按鍵按下。如對第一行掃描就令P1.0為低,P1口其余為高,這樣若第一行有鍵按下,則P1口的值就會由0xfe變?yōu)槠渌?,再由這個值來確定是哪個鍵按下。 以下為鍵盤掃描子程序的程序清單。 uchar keyscan(){ int i; P1=0xfe; temp=P1; temp=temp&0xf0;大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 while(temp!=0xf0){ delay(5); temp=P1; temp=temp&0xf0; while(temp!=0xf0) { temp=P1; switch(temp) { case 0xee:{rdat++;num=1;left(rdat,num);} break; case 0xde:{rdat++;num=2;left(rdat,num);} break; case 0xbe:{rdat++;num=3;left(rdat,num);} break; case 0x7e:{rdat++;num=4;left(rdat,num);} break; } while(temp!=0xf0) { temp=P1; temp=temp&0xf0; } } } P1=0xfd;temp=P1;temp=temp&0xf0;while(temp!=0xf0){ delay(5); temp=P1; temp=temp&0xf0; while(temp!=0xf0) { temp=P1; switch(temp) { case 0xed:{rdat++;num=5;left(rdat,num);} break; case 0xdd:{rdat++;num=6;left(rdat,num);} break;大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 } case 0xbd:{rdat++;num=7;left(rdat,num);} break; case 0x7d:{rdat++;num=8;left(rdat,num);} break;} while(temp!=0xf0){ temp=P1; temp=temp&0xf0;} } P1=0xfb;temp=P1;temp=temp&0xf0;while(temp!=0xf0){ delay(5); temp=P1; temp=temp&0xf0; while(temp!=0xf0) { temp=P1; switch(temp) { case 0xeb:{rdat++;num=9;left(rdat,num);} break; case 0xdb:{rdat++;num=10;left(rdat,num);} break; case 0xbb:{equ();} break; case 0x7b:{rdat=0;add=0;subb=0;mul=0;div=0; result=0; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break; } while(temp!=0xf0) { temp=P1; temp=temp&0xf0; } 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 } } P1=0xf7;temp=P1;temp=temp&0xf0;while(temp!=0xf0){ delay(5); temp=P1; temp=temp&0xf0; while(temp!=0xf0) { temp=P1; switch(temp) { case 0xe7:{rdat=0;add=1;subb=0;mul=0;div=0; for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } result=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break; case 0xd7:{rdat=0;add=0;subb=1;mul=0;div=0; for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } result=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break; case 0xb7:{rdat=0;add=0;subb=0;mul=1;div=0; for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } result=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break; case 0x77:{rdat=0;add=0;subb=0;mul=0;div=1;大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 } return num;} } while(temp!=0xf0){ temp=P1; temp=temp&0xf0;} } for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } result=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break;4.2移位子程序及結(jié)果計(jì)算子程序設(shè)計(jì) 輸入數(shù)據(jù)要存儲在一四位數(shù)組內(nèi),而我們鍵入的值是數(shù)據(jù)的高位,后鍵入的值是低位,這樣我們就需要在輸入低位數(shù)值時(shí)將高位數(shù)值從數(shù)組的低位移向數(shù)組的高位,這就是編寫移位子程序的目的。 對于結(jié)果計(jì)算子程序,包含加、減、乘、除四種運(yùn)算。以加法運(yùn)算為例,各種運(yùn)算各有其標(biāo)志位來代表計(jì)算類型,當(dāng)加法標(biāo)志位add=1是,就將輸入的兩個數(shù)據(jù)按照加法進(jìn)行計(jì)算。 首先將數(shù)組內(nèi)的數(shù)按照對應(yīng)的位關(guān)系,將其轉(zhuǎn)化為一個十進(jìn)制數(shù),這樣我們就得到了加速和被加數(shù)這樣倆個十進(jìn)制數(shù),從而我們就可以簡單的將兩個數(shù)進(jìn)行相加,結(jié)果就是我們所求的數(shù)值。但這個數(shù)值不能直接顯示到數(shù)碼管上,我們還要對其進(jìn)行處理,使其變?yōu)閷?yīng)進(jìn)位的四個數(shù)存入數(shù)組內(nèi),以便顯示。既通過對結(jié)果數(shù)值分別除以1000、100、10和對10取余,得到我們想要的四個數(shù),送顯示子程序顯示。其余減、乘、除的計(jì)算方法與加法的計(jì)算方法一樣,這里不再累述。 以下為移位子程序和結(jié)果計(jì)算子程序的程序清單。 void left(uchar rx,uchar date){ switch(rx) { case 1:dat[0]=date;break;大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 void equ(){ int i,j,k; long int s; if(add==1){for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } s=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; result=result+s;add=0;} if(subb==1){for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } s=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; result=result-s;subb=0;} if(mul==1){for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } s=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; result=result*s;mul=0; } if(div==1){for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } s=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; result=result/s;div=0; } If(result>9999){dat[0]=11;dat[3]=dat[2]=dat[1]=0;} if(result<=9999) { dat[0]=result%10; dat[1]=(result/10)%10; dat[2]=(result/100)%10; dat[3]=(result/1000)%10; } for(j=3;j>0;j--) { if(dat[j]>0) { case 2:dat[1]=dat[0],dat[0]=date;break; case 3:dat[2]=dat[1],dat[1]=dat[0],dat[0]=date;break; case 4:dat[3]=dat[2],dat[2]=dat[1],dat[1]=dat[0],dat[0]=date;break; } } 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 for(k=j-1;k>=0;k--) { if(dat[k]==0){dat[k]=10;} } } } if(dat[0]==0){dat[0]=10;} } 4.3顯示子程序設(shè)計(jì) 從始至終無論是輸入的計(jì)算數(shù)據(jù),還是計(jì)算后的結(jié)果值。都存儲在同一數(shù)組dat[ ]中,這樣我們只要在顯示時(shí)一直調(diào)用dat[ ]中的值,就能正確的顯示數(shù)據(jù)。 以下為顯示子程序的程序清單。 void display(){ uchar aa; keyscan(); P2=0x07; aa=dat[0]; P0=table[aa]; P2=0x27; delay(3); P2=0x0b; aa=dat[1]; P0=table[aa]; P2=0x2b; delay(3); P2=0x0d; aa=dat[2]; P0=table[aa]; P2=0x2d; delay(3); P2=0x0e; aa=dat[3]; P0=table[aa]; P2=0x2e; delay(3); } 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 4.4主程序設(shè)計(jì) 主程序既把以上各子程序串連成一個整體,使整個程序循環(huán)運(yùn)行。而在以上程序中也已經(jīng)加入了個程序之間的連接點(diǎn),首先進(jìn)入程序后就立即進(jìn)入顯示子程序,而顯示子程序內(nèi)又調(diào)用鍵盤掃描子程序,若有鍵按下,則會跳轉(zhuǎn)到移位子程序和結(jié)果計(jì)算子程序進(jìn)行相應(yīng)的處理。通過計(jì)算或移位后,數(shù)組內(nèi)的值發(fā)生改變,顯示的值也會同時(shí)發(fā)生改變。之后再進(jìn)行鍵盤掃描,如此反復(fù)運(yùn)行,就構(gòu)成了程序的整體。 以下為主程序清單。 void main(){ num=0; while(1) { display(); } } 整體程序清單見附錄二。 五、調(diào)試及性能分析 5.1調(diào)試步驟 在焊接好器件后,先不要將芯片插在芯片座上,要先驗(yàn)證先板上電源是否好用,有無短路等。接上USB電源,用萬用表測量個芯片座對應(yīng)電源和地之間的電壓值,觀察電壓值是否正常。一切正常后方可將芯片插入芯片座,以繼續(xù)測試其他功能。 將芯片插上后,對各個模塊進(jìn)行調(diào)試,按鍵是否工作正常,數(shù)碼管是否顯示正常等。編寫相關(guān)部分的測試程序?qū)ζ溥M(jìn)行測試。 各部分硬件檢測無誤后,下載程序進(jìn)行整體調(diào)試,一切正常后,結(jié)束調(diào)試過程。 在具體調(diào)試時(shí)首先遇到的問題是程序無法下載進(jìn)入單片機(jī),通過將電路板接線與原理電路圖接線的對比發(fā)現(xiàn),串口芯片與單片機(jī)連接的輸入,輸出接反,重新用銅線連接后,依然無法下載程序。后找到原因是由于下載串口與設(shè)計(jì)封裝不符,用相對應(yīng)的下載線可以下載。 成功下載程序后,發(fā)現(xiàn)數(shù)碼管顯示不正確,查看后發(fā)現(xiàn)有先沒有連接,可能是制板時(shí)漏印,連接后顯示正常。大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 5.2性能分析 對于計(jì)算器的性能,主要的衡量指標(biāo)就在于計(jì)算的精度,本次制作的計(jì)算器性能情況如下: 加法運(yùn)算:四位加法運(yùn)算,和值不超過9999,若超過上限,則顯示錯誤提示E,蜂鳴器報(bào)警提示。 減法運(yùn)算:四位減法運(yùn)算,若結(jié)果為負(fù),對其取絕對值。 乘法運(yùn)算:積不超過9999的乘法運(yùn)算,若超出上限,顯示錯誤提示E,蜂鳴器報(bào)警提示。 除法運(yùn)算:整數(shù)除法,既計(jì)算結(jié)果為整數(shù),若除數(shù)為零,則顯示錯誤提示E,蜂鳴器報(bào)警提示。 通過對實(shí)際性能的分析,可以得到本次設(shè)計(jì)滿足設(shè)計(jì)的要求。 六、心得體會 通過本次課程設(shè)計(jì)我真正的自己完成了對給定要求系統(tǒng)的硬件設(shè)計(jì)、電路設(shè)計(jì)、電路板設(shè)計(jì)、軟件設(shè)計(jì)以及對成品的調(diào)試過程。從整個過程中學(xué)習(xí)到了很多方面的知識,了解到以往學(xué)習(xí)中自己知識在某方面的不足之處,是對以往學(xué)習(xí)科目的一種貫穿和承接,從而能更好的認(rèn)識和學(xué)習(xí),也對將來從事工作大有裨益。 從本次課設(shè)中我也看到了自身的很多不足之處,對知識的掌握不夠扎實(shí),有一知半解的現(xiàn)象。有時(shí)做事不夠穩(wěn)定,過于毛躁,不能平心靜氣的去分析所遇到的問題和錯誤。這在以后的工作和生活中是不可取的,通過對自身問題的認(rèn)識與改正相信再遇到同樣問題時(shí)會更好的解決。以后的設(shè)計(jì)實(shí)驗(yàn)也會更好的完成。 參考文獻(xiàn) [1] 徐維祥、劉旭敏.單片微型機(jī)原理及應(yīng)用.大連:大連理工大學(xué)出版社,1996 [2] 李光飛、樓然苗、胡佳文、謝象佐.單片機(jī)課程設(shè)計(jì)與實(shí)例指導(dǎo).北京: 北京航空航天大學(xué)出版社,2004 [3] 余永權(quán).89系列FLASH單片機(jī)原理及應(yīng)用.北京:電子工業(yè)出版社,2002 [4] 李群芳,黃建.單片機(jī)微型計(jì)算機(jī)與接口技術(shù).北京:電子工業(yè)出版社,2001 [5] 樓然苗、李光飛.51系列單片機(jī)設(shè)計(jì)實(shí)例.北京:北京航空航天大學(xué)出版社,2003 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 附錄1 系統(tǒng)硬件電路圖 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 附錄2 程序清單 #include for(y=110;y>0;y--);} void display();void main(){ num=0; while(1) { display(); } } void display(){ uchar aa; keyscan(); P2=0x07; aa=dat[0];大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 P0=table[aa]; P2=0x27; delay(3); P2=0x0b; aa=dat[1]; P0=table[aa]; P2=0x2b; delay(3); P2=0x0d; aa=dat[2]; P0=table[aa]; P2=0x2d; delay(3); P2=0x0e; aa=dat[3]; P0=table[aa]; P2=0x2e; delay(3); } uchar keyscan(){ int i; P1=0xfe; temp=P1; temp=temp&0xf0; while(temp!=0xf0) { delay(5); temp=P1; temp=temp&0xf0; while(temp!=0xf0) { temp=P1; switch(temp) { case 0xee:{rdat++;num=1;left(rdat,num);} break; case 0xde:{rdat++;num=2;left(rdat,num);} break; case 0xbe:{rdat++;num=3;left(rdat,num);} break;大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 } case 0x7e:{rdat++;num=4;left(rdat,num);} break;} while(temp!=0xf0){ temp=P1; temp=temp&0xf0;} } P1=0xfd;temp=P1;temp=temp&0xf0;while(temp!=0xf0){ delay(5); temp=P1; temp=temp&0xf0; while(temp!=0xf0) { temp=P1; switch(temp) { case 0xed:{rdat++;num=5;left(rdat,num);} break; case 0xdd:{rdat++;num=6;left(rdat,num);} break; case 0xbd:{rdat++;num=7;left(rdat,num);} break; case 0x7d:{rdat++;num=8;left(rdat,num);} break; } while(temp!=0xf0) { temp=P1; temp=temp&0xf0; } } } P1=0xfb;temp=P1;大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 temp=temp&0xf0;while(temp!=0xf0){ delay(5); temp=P1; temp=temp&0xf0; while(temp!=0xf0) { temp=P1; switch(temp) { case 0xeb:{rdat++;num=9;left(rdat,num);} break; case 0xdb:{rdat++;num=10;left(rdat,num);} break; case 0xbb:{equ();} break; case 0x7b:{rdat=0;add=0;subb=0;mul=0;div=0; result=0; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break; } while(temp!=0xf0) { temp=P1; temp=temp&0xf0; } } } P1=0xf7;temp=P1;temp=temp&0xf0;while(temp!=0xf0){ delay(5); temp=P1; temp=temp&0xf0; while(temp!=0xf0) { temp=P1; switch(temp)大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 { case 0xe7:{rdat=0;add=1;subb=0;mul=0;div=0; for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } result=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break; case 0xd7:{rdat=0;add=0;subb=1;mul=0;div=0; for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } result=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break; case 0xb7:{rdat=0;add=0;subb=0;mul=1;div=0; for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } result=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break; case 0x77:{rdat=0;add=0;subb=0;mul=0;div=1; for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } result=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; dat[0]=10;dat[1]=dat[2]=dat[3]=0; } break; } while(temp!=0xf0) { temp=P1; temp=temp&0xf0; } } 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 } return num;} void left(uchar rx,uchar date){ switch(rx) { case 1:dat[0]=date;break; case 2:dat[1]=dat[0],dat[0]=date;break; case 3:dat[2]=dat[1],dat[1]=dat[0],dat[0]=date;break; case 4:dat[3]=dat[2],dat[2]=dat[1],dat[1]=dat[0],dat[0]=date;break; } } void equ(){ int i,j,k;long int s; if(add==1){for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } s=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; result=result+s;add=0;} if(subb==1){for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } s=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; if(s>result){result=s-result;} else result=result-s;subb=0;} if(mul==1){for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } s=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; result=result*s;mul=0; } 大連民族學(xué)院2007級電子信息工程專業(yè)單片機(jī)系統(tǒng)課程設(shè)計(jì)報(bào)告 if(div==1){for(i=0;i<5;i++){ if(dat[i]==10){dat[i]=0;} } s=dat[0]+10*dat[1]+100*dat[2]+1000*dat[3]; if(s==0)result=10000; else result=result/s;div=0; } if(result>9999){dat[0]=11;dat[3]=dat[2]=dat[1]=0;} if(result<=9999){ dat[0]=result%10;dat[1]=(result/10)%10;dat[2]=(result/100)%10;dat[3]=(result/1000)%10;} for(j=3;j>0;j--) { if(dat[j]>0) { for(k=j-1;k>=0;k--) { if(dat[k]==0){dat[k]=10;} } } } if(dat[0]==0){dat[0]=10;} } 22 課 程 設(shè) 計(jì) 課程名稱 Java語言課程設(shè)計(jì) 題目名稱 人事管理系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn) 學(xué)生學(xué)院 應(yīng)用數(shù)學(xué)學(xué)院 專業(yè)班級 學(xué) 號 學(xué)生姓名 指導(dǎo)教師 劉科峰 2014 年 10 月 29 日 一.設(shè)計(jì)內(nèi)容 自學(xué)Swing圖形界面設(shè)計(jì)和數(shù)據(jù)庫程序設(shè)計(jì)。開發(fā)用于某單位的人事管理系統(tǒng)。該系統(tǒng)要求實(shí)現(xiàn)以下功能: 1.員工信息管理包括:員工信息一覽表、新員工的建立、修改 2.薪資福利管理:考勤與薪資的連動計(jì)算、薪資與福利的設(shè)置 3.考勤假期管理:考勤項(xiàng)目錄入, 實(shí)現(xiàn)考勤信息的查詢、統(tǒng)計(jì)、匯總 4.人事報(bào)表管理:按照員工性別,數(shù)目,薪酬自動生成相關(guān)報(bào)表, 可自定義統(tǒng)計(jì)分析條件并可對歷史報(bào)表進(jìn)行管理。 設(shè)計(jì)亮點(diǎn) 1.null布局方式 Swing圖形界面設(shè)計(jì)中有很多布局方式,通過本次學(xué)習(xí)了解到了FlowLayout,BorderLayout,GridLayout以及null布局,就這四種布局方式而言,null布局的優(yōu)點(diǎn)在于可以將組建的位置精準(zhǔn)到坐標(biāo)值,可以把組件放到任意想放置的位置,另外可以通過null去設(shè)置組件的大小,相較于其他布局方式來說是一個很大的優(yōu)勢。但同時(shí)它的缺點(diǎn)在于不能根據(jù)Frame的大小變化而改變位置。 2.組件部分屬性的設(shè)計(jì) Swing中有很多方法是用來實(shí)現(xiàn)組件屬性設(shè)置的,比如button.setVisible(false);按鈕通過調(diào)用這個方法實(shí)現(xiàn)不可見,這是我此次課程設(shè)計(jì)中的一個亮點(diǎn),因?yàn)榻M件是沒有設(shè)置大小的方法的,只有依靠于相應(yīng)的布局方式才能改變它的大小,通過設(shè)置多幾個按鈕設(shè)為不可見,將所要可見按鈕實(shí)現(xiàn)大小以及位置的控制是一種很好的方法。 二、設(shè)計(jì)方案 1主界面(只列出界面設(shè)計(jì)方面的代碼) JPanel panel=new JPanel();JTable table=null;JButton ibtn=new JButton(“員工信息”);JButton cbtn=new JButton(“考勤管理”);JButton mbtn=new JButton(“薪資管理”);JButton tbtn=new JButton(“人事報(bào)表”);ImageIcon rtou = new ImageIcon(“rentou.jpg”); JLabel imgLabel=new JLabel(rtou); //上面代碼定義了一個面板與四個標(biāo)簽,并引入了一個圖片 panel.setLayout(new FlowLayout());//設(shè)置面板為流布局 panel.add(ibtn);panel.add(cbtn);panel.add(mbtn);panel.add(tbtn);panel.setBackground(Color.GRAY); //將按鈕加到面板中,設(shè)置面板為灰色 this.add(imgLabel,BorderLayout.CENTER);this.add(panel,BorderLayout.SOUTH);this.setBounds(300, 180, 600, 350);this.setVisible(true);this.getContentPane().setBackground(Color.GRAY);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/*圖片標(biāo)簽以邊框布局放置在中間,將面板也以邊框布局放置在下面,可見,灰色,點(diǎn)擊關(guān)閉程序*/ (2)查詢員工界面(只列出界面設(shè)計(jì)方面的代碼) Label idlabel = new JLabel(“ID”);JLabel namelabel = new JLabel(“姓名”);JLabel bumenlabel = new JLabel(“部門”);JLabel zhiweilabel = new JLabel(“職位”); JTextField idfiled = new JTextField(8);JTextField namefield = new JTextField(8);JComboBox bumenbox =new JComboBox();JComboBox zhiweubox = new JComboBox(); JButton btn=new JButton(“查詢”);JButton ibtn=new JButton(“添加”) JPanel spanel=new JPanel();JPanel vpanel=new JPanel(); /*定義和各個組件,4個標(biāo)簽,兩個文本框,兩個復(fù)選框,兩個按鈕,兩個面板容器*/ spanel.setLayout(new FlowLayout()); vpanel.setLayout(new FlowLayout(FlowLayout.CENTER,45,25)); bumenbox.addItem(“"); bumenbox.addItem(”管理部“); bumenbox.addItem(”生產(chǎn)部“); bumenbox.addItem(”業(yè)務(wù)部“); zhiweubox.addItem(”“); zhiweubox.addItem(”部長“); zhiweubox.addItem(”副部長“); zhiweubox.addItem(”普工“); spanel.add(idlabel); spanel.add(idfiled); spanel.add(namelabel); spanel.add(namefield); spanel.add(bumenlabel); spanel.add(bumenbox); spanel.add(zhiweilabel); spanel.add(zhiweubox); spanel.add(btn); vpanel.add(ibtn); spanel.setBackground(Color.GRAY); vpanel.setBackground(Color.GRAY); //將各個組件放進(jìn)對應(yīng)面板,設(shè)置相關(guān)屬性 this.add(spanel,BorderLayout.NORTH); this.add(vpanel,BorderLayout.SOUTH); this.setBounds(300, 180, 600, 350); this.setVisible(true); this.getContentPane().setBackground(Color.GRAY); //將面板以邊框布局放入框架中,設(shè)置屬性(3)增加員工信息界面 JPanel panel=new JPanel(); JLabel timeLabel=new JLabel(”時(shí)間“);JLabel allnumLabel=new JLabel(”員工總數(shù)“); JLabel staffMoLabel=new JLabel(”考勤“);JLabel entryLabel=new JLabel(”全勤“); JLabel quitLabel=new JLabel(”缺勤“);JLabel mwLabel=new JLabel(”性別比例“); JLabel manLabel=new JLabel(”男“); JLabel womanLabel=new JLabel(”女“);JLabel proportionLabel=new JLabel(”男女比例“);JLabel distributionLabel=new JLabel(”人員部門分布“);JLabel mdpLabel=new JLabel(”管理部“); JLabel pdpLabel=new JLabel(”生產(chǎn)部“);JLabel bdpLabel=new JLabel(”業(yè)務(wù)部“);JLabel xmLabel=new JLabel(”項(xiàng)目“);JLabel xzLabel=new JLabel(”細(xì)則“);JLabel stLabel=new JLabel(”數(shù)據(jù)統(tǒng)計(jì)“); JTextField timeFiled = new JTextField(8); JTextField allnumFiled = new JTextField(8);JTextField entryFiled = new JTextField(8);JTextField quitFiled = new JTextField(8);JTextField manFiled = new JTextField(8);JTextField womanFiled = new JTextField(8);JTextField proportionFiled = new JTextField(8);JTextField mdpFiled = new JTextField(8);JTextField pdpFiled = new JTextField(8);JTextField bdpFiled = new JTextField(8);// 定義所需組件 public Selectrenshi(String tablename){ super(”人事管理“); panel.setLayout(null); panel.setBackground(Color.GRAY); panel.add(xmLabel); panel.add(xzLabel); panel.add(stLabel); panel.add(timeLabel); panel.add(timeFiled); panel.add(allnumLabel); panel.add(allnumFiled); panel.add(staffMoLabel); panel.add(entryLabel); panel.add(entryFiled); panel.add(quitLabel); panel.add(quitFiled); panel.add(mwLabel); panel.add(manLabel); panel.add(manFiled); panel.add(womanLabel); panel.add(womanFiled); panel.add(proportionLabel); panel.add(proportionFiled); panel.add(distributionLabel); panel.add(mdpLabel); panel.add(mdpFiled); panel.add(pdpLabel); panel.add(pdpFiled); panel.add(bdpLabel); panel.add(bdpFiled); //將組件加到相應(yīng)面板中 xmLabel.setBounds(120,20,100,30); xzLabel.setBounds(240,20,100,30); stLabel.setBounds(360,20,100,30); timeLabel.setBounds(120,50,100,30); timeFiled.setBounds(360,50,100,30); allnumLabel.setBounds(120,100,100,30); allnumFiled.setBounds(360,100,100,30); staffMoLabel.setBounds(120,150,100,30); entryLabel.setBounds(240,150,100,30); entryFiled.setBounds(360,150,100,30); quitLabel.setBounds(240,200,100,30); quitFiled.setBounds(360,200,100,30); mwLabel.setBounds(120,250,100,30); manLabel.setBounds(240,250,100,30); manFiled.setBounds(360,250,100,30); womanLabel.setBounds(240,300,100,30); womanFiled.setBounds(360,300,100,30); proportionLabel.setBounds(240,350,100,30); proportionFiled.setBounds(360,350,100,30); distributionLabel.setBounds(120,400,100,30); mdpLabel.setBounds(240,400,100,30); mdpFiled.setBounds(360,400,100,30); pdpLabel.setBounds(240,450,100,30); pdpFiled.setBounds(360,450,100,30); bdpLabel.setBounds(240,500,100,30); bdpFiled.setBounds(360,500,100,30); //采用null布局,設(shè)置組建坐標(biāo)值 this.add(panel,BorderLayout.CENTER); this.setBounds(300, 100, 600, 600); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.getContentPane().setBackground(Color.GRAY); //將面板放入框架,設(shè)置相應(yīng)屬性(4)員工考勤界面 JLabel idlabel = new JLabel(”ID“);JComboBox idbox =new JComboBox();CheckTable model = null; JButton wbtn=new JButton(”修改“); JButton cbtn=new JButton(”查詢“);JButton mbtn=new JButton(”創(chuàng)建薪資表“);JButton rbtn=new JButton(”創(chuàng)建人事表“); JScrollPane scrollpane = null;JPanel spanel=new JPanel();JPanel vpanel=new JPanel();JTable table=null;spanel.add(idbox);panel.add(wbtn);spanel.add(cbtn);vpanel.add(mbtn);vpanel.add(rbtn);spanel.setBackground(Color.GRAY);vpanel.setBackground(Color.GRAY);this.add(spanel,BorderLayout.NORTH);this.add(vpanel,BorderLayout.SOUTH);this.setBounds(300, 180, 600, 350);this.setVisible(true);this.getContentPane().setBackground(Color.GRAY); (5)選擇考勤表界面 JLabel checklabel = new JLabel(”選擇考勤表“);JLabel newlabel = new JLabel(”創(chuàng)建考勤表“);JComboBox timebox =new JComboBox();JTextField newfield = new JTextField();JButton btn=new JButton(”確認(rèn)“);JButton nbtn=new JButton(”創(chuàng)建");JPanel spanel=new JPanel();spanel.add(checklabel); spanel.add(timebox); spanel.add(btn); spanel.add(newlabel); spanel.add(newfield); spanel.add(nbtn); checklabel.setBounds(30,90,100,30); timebox.setBounds(180,90,100,30); btn.setBounds(360,90,100,30); newlabel.setBounds(30,200,100,30); newfield.setBounds(180,200,100,30); nbtn.setBounds(360,200,100,30); this.add(spanel); this.setBounds(300, 180, 600, 350); this.setVisible(true); 三、結(jié)果和數(shù)據(jù)處理 四、結(jié)論 1.Swing圖形界面 圖形用戶界面(GUI)是程序不可或缺的一部分,它便于用戶和程序的交互。在Swing界面中是以Frame為框架,采用合理的布局方式(FlowLayout,BorderLayout,GridLayout,null),將Panel加入框架之中,而實(shí)現(xiàn)界面的各個組件將調(diào)用各種方法設(shè)置自身屬性實(shí)行可視化界面以及加入到面板之中。再通過事件監(jiān)聽器實(shí)現(xiàn)事件的監(jiān)聽預(yù)處理機(jī)制。 2.數(shù)據(jù)庫 在這次課程設(shè)計(jì)中哦我主要負(fù)責(zé)Swing圖像界面,對于數(shù)據(jù)庫只做了最簡單的了解。程序中采用了最流行的關(guān)系型數(shù)據(jù)庫mysql,雪化了mysql的建立,刪除,與修改以及使用sql語言對數(shù)據(jù)庫進(jìn)行一些簡單的操作,將按鈕等設(shè)置的監(jiān)聽事件與數(shù)據(jù)庫相連接。 五、問題與討論 1.組件的方法調(diào)用 在這次課程設(shè)計(jì)中,用到了很多的組件,例如Button,Jlabel,TextField,ComBox,等。Swing圖形界面也確實(shí)提供了很多方法去設(shè)置相關(guān)組件的屬性,例如label.setVisible(false);設(shè)置標(biāo)簽不可見等很多方法,只要查看API文檔幾乎就能實(shí)現(xiàn)很多功能,但是對于按鈕等最常見的組件來說設(shè)置大小如果不依靠相關(guān)布局方式很難設(shè)置,我在程序中之所以運(yùn)用了很多的bull布局方式就是為了實(shí)現(xiàn)組件大小的設(shè)置,如果說能有一個方法直接設(shè)置組件大小而不受其他組件或容器影響就能使代碼很簡潔了。2.相對布局 在編寫圖像界面的程序的時(shí)候,我用了很多的布局方式,有FlowLayout,BorderLayout,GrirLayout,null等,其中null布局用的最多。null布局的優(yōu)點(diǎn)在于可以將組建的位置精準(zhǔn)到坐標(biāo)值,可以把組件放到任意想放置的位置,另外可以通過null去設(shè)置組件的大小,相較于其他布局方式來說是一個很大的優(yōu)勢。但同時(shí)它的缺點(diǎn)在于不能根據(jù)Frame的大小變化而改變位置。其他三種布局方式雖然實(shí)現(xiàn)了歲Frame大小變動而改變組件大小及位置但是不容易控制,如果null布局能實(shí)現(xiàn)相對布局就是很好的一種布局方式了。 《Java語言程序設(shè)計(jì)》 題 目:指導(dǎo)老師:姓 名:專 業(yè):班 級:日 期:課程設(shè)計(jì)報(bào)告 目 錄 一、系統(tǒng)總體設(shè)計(jì).......................................1 (一)設(shè)計(jì)目標(biāo)及完成功能..............................1 (二)系統(tǒng)結(jié)構(gòu)設(shè)計(jì)...................................1 二、數(shù)據(jù)庫設(shè)計(jì)........................................1 三、詳細(xì)設(shè)計(jì)..........................................1(一)界面設(shè)計(jì)........................................1(二)系統(tǒng)設(shè)計(jì)........................................2(三)關(guān)鍵技術(shù)及算法..................................2 四、測試..............................................2 五、安裝使用說明.......................................2 總結(jié)(體會)..........................................2 參考文獻(xiàn):............................................2 《Java語言程序設(shè)計(jì)》課程設(shè)計(jì)報(bào)告 一、系統(tǒng)總體設(shè)計(jì) (一)設(shè)計(jì)目標(biāo)及完成功能 此部分可以包括如下內(nèi)容: 1.窗口功能說明:設(shè)計(jì)了幾個窗口,分別實(shí)現(xiàn)什么功能.2.菜單欄或工具欄說明:如果設(shè)計(jì)了菜單或工具欄,分別說明包括哪些項(xiàng)及其各自實(shí)現(xiàn)什么操作.…… (二)系統(tǒng)結(jié)構(gòu)設(shè)計(jì) 說明:要繪出系統(tǒng)結(jié)構(gòu)圖 二、數(shù)據(jù)庫設(shè)計(jì) 必須包含以下內(nèi)容:E-R圖(說明所有實(shí)體及其屬性)、表結(jié)構(gòu)列表(字段名、類型、主鍵、備注等)。 沒有用到數(shù)據(jù)庫的不用寫此部分 三、詳細(xì)設(shè)計(jì) (一)界面設(shè)計(jì) 界面抓圖,圖要有編號和標(biāo)題(格式:圖1 主界面圖),位于圖的下方居中對齊。 《Java語言程序設(shè)計(jì)》課程設(shè)計(jì)報(bào)告 (二)系統(tǒng)設(shè)計(jì) 1.共設(shè)計(jì)了幾個類或接口,是否有繼承關(guān)系,各實(shí)現(xiàn)什么功能,繪圖(列表)說明。 2.列表說明各類的方法及其功能。 (三)關(guān)鍵技術(shù)及算法 使用的主要算法分析、關(guān)鍵技術(shù)說明。如數(shù)據(jù)庫連接技術(shù)、加密解密算法等。 四、測試 五、安裝使用說明 1.系統(tǒng)配置說明。是否需要配置數(shù)據(jù)源或安裝補(bǔ)丁包、導(dǎo)入數(shù)據(jù)庫等。 2.登錄的用戶名、密碼。3.其他特殊說明。 總結(jié)(體會) (談?wù)劚敬握n程設(shè)計(jì)的心得體會) 參考文獻(xiàn): [1] 竇萬峰.軟件工程方法與實(shí)踐[M].機(jī)械工業(yè)出版社,2009 [2] 李兆鋒,張得生.Java Web項(xiàng)目開發(fā)案例精粹[M].電子工業(yè)出版社,2010 [3] 沈澤剛,秦玉平.Java Web編程技術(shù)[M].清華大學(xué)出版社,2009 《Java語言程序設(shè)計(jì)》課程設(shè)計(jì)報(bào)告 包括書籍、網(wǎng)站、論壇等。 說明:(以下內(nèi)容作為要求) 正文部分一律用小四號字,宋體,1.5倍行距。一級大標(biāo)題黑體四號字靠左,加粗。二級大標(biāo)題黑體四號靠左,不加粗。 參考文獻(xiàn): (要求:五號字,宋體,左對齊,懸掛縮進(jìn),單倍行距。按作者、書名、出版社、出版時(shí)間格式逐一列出)第二篇:Matlab課程設(shè)計(jì)報(bào)告(簡單計(jì)算器)
第三篇:單片機(jī)計(jì)算器課程設(shè)計(jì)報(bào)告
第四篇:Java課程設(shè)計(jì)報(bào)告
第五篇:java課程設(shè)計(jì)報(bào)告