組員:
林偉欽:201421122025 柳澤峰:201421122011
項目位址:
Coding.net: https://git.coding.net/Aes/Exp2.git
視訊位址:
http://v.youku.com/v_show/id_XMzEwMjYyOTI3Ng==.html?spm=a2h3j.8428770.3416059.1
本次作業完成的題目内容:
1.實作GUI;
2.輸入運算最大操作數,生成題目的數量,送出檢查對錯,錯誤的話,顯示正确的答案,并記錄使用者的對錯總數,程式退出再啟動的時候,能把以前的對錯數量儲存并在此基礎上增量計算,并且支援10000道題目的生成;
3.有計時功能,能顯示使用者開始答題後的消耗時間;
4.當生成題目較多時,有滾動條,使得界面簡潔好看。
需求分析:
GUI: 分為三份界面,由于使用Java的圖形化界面,使用swing來實作的,是以分為三個容器,分别是菜單面闆(menuPanel),主面闆(scrollPane),結果面闆(resultPanel)。
在菜單面闆輸入生成題目數量,運算的最大操作數,計時顯示;在主面闆中,自動生題目,在使用者送出後,檢查對錯,錯誤的測試把正确的答案顯示出來;在結果面闆中顯示本次答對數目,答錯數目,正确率,還有總共答對題目數,答錯題目數,總的正确率。
記錄 : 要把每次生成題目紀錄下來,還有對錯結果總數記錄下來,以及問題的答案記錄下來,紀錄本地檔案中。
計時: 當輸入題目數目及運算最大操作數送出後,使用者就開始答題,從零開始計時,并顯示在菜單面闆中。
滾動條: 當生成的題目數量超過9道題目時,根據題目的多少,在主面闆中實作滾動條,使得界面簡潔好看。
思維導圖:

代碼展示(我做的是計時跟題目顯示的滾動條):
計時單獨實作:
@SuppressWarnings("deprecation")
public KeepTime2(){
super("四則運算");
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
setBounds(550, 270, 200, 150);
final Timer timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
Date now2 = new Date(now.getTime() + 1000);
now = now2;
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
lab.setText(formatter.format(now));
}
});
btnStart.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Button b = (Button) e.getSource();
b.setLabel("開始測試");
timer.start();
}
});
btnEnd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Button b = (Button) e.getSource();
b.setLabel("結束測試");
timer.stop();
}
});
this.add(btnStart);
this.add(btnEnd);
this.add(lab);
this.setLayout(new FlowLayout());
this.setSize(600, 800);
this.setLocation(200, 150);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
滾動條先是單獨實作:
public class Test extends JFrame {
JPanel menuPanel = new JPanel();
JScrollPane scrollPane = new JScrollPane();
JPanel mainPanel = new JPanel();
JTextArea textArea = new JTextArea();
JPanel resultPanel = new JPanel();
public Test(){
//resultPanel.setVisible(false);
//addContToMenu(menuPanel, scrollPane, resultPanel);
//addContToResult(resultPanel);
mainPanel.setBorder(new EmptyBorder(5,5,5,5));
mainPanel.setLayout(new BorderLayout(0,0));
//scrollPane=new JScrollPane(mainPanel);
this.setContentPane(mainPanel);
mainPanel.add(scrollPane,BorderLayout.CENTER);
textArea=new JTextArea();
//scrollPane.add(textArea);
scrollPane.setViewportView(textArea);
menuPanel.add(new JButton("測試"));
//scrollPane.add(new JButton("測試"));
resultPanel.add(new JButton("測試"));
this.add(menuPanel, BorderLayout.NORTH);
this.add(scrollPane, BorderLayout.CENTER);
this.add(resultPanel, BorderLayout.SOUTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 100, 250, 200);
this.setVisible(true);
}
public static void main(String[] args) {
new Test();
}
}
這樣的實作是主流的做法,但是由于我們的程式題目是生成在一個主面闆JPanel中,中間使用了一行的元件JTextField,是以一個主流的多行元件JTextArea并不适用。
是以改動成、成為一下使用面闆JPanel,然後添加到JScrollPane這個裡面。
public class Test2 extends JFrame {
private static final long serialVersionUID = 1L;
public Test2() {
super("TestJScrollPane");
this.setLayout(null);
this.setBounds(200, 200, 200, 300);
JLabel label = new JLabel("測試");
JPanel panel = new JPanel();
panel.add(label);
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setBounds(100, 100, 100, 300);
/**
* 要加滾動條就要讓panel的寬高大于scrollPane的寬高..你隻要上下的..隻要高大于就行了..
*/
panel.setPreferredSize(new Dimension(scrollPane.getWidth() - 50,
scrollPane.getHeight() * 2));
this.add(scrollPane);
panel.revalidate(); // 告訴其他部件,我的寬高變了
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Test2();
}
}
這個單獨實作比較簡單,但是把這個添加到我們程式的主界面,難度就加大了。
程式運作:
Answer.txt用來存正确的題目答案; result.txt用來存答對答錯的總題目數量; timu.txt用來存放生成的題目。
小結感受:
在結對程式設計中,1 + 1 >2是肯定的,每個人的想法都有一定的偏差,通過交流,就可以變成好幾個想法。隊友的程式設計能力比較強,也是以,自己這段時間在有目的的學習一些東西,學習帶有目的性,而且要抓緊時間做,這段時間對Java的Swing圖形化界面有了很好的學習與見解,但是同時,這個Java的圖形化界面确實不是很好用。我的程式設計基礎較差,有些拖隊友的後腿,隊友很耐心的在這段時間教會我許多東西,我也對此了解了更多的辦法去完成需要完成的目标,感謝隊友!我們這次兩人命名方法有些不同,是以下次應該在使用前就提前定好各自類的命名。
評價合作夥伴:
柳兄是一個很有規劃的人,安排好時間段做不同的事情,而且做事的專注度很高,很有耐心。對待命名很嚴謹,一開始的mainPanel,被我改成滾動面闆,我就習慣命名scrollPane。顯而易見,因為是主面闆,他的命名更好。他的程式設計習慣,風格都值得我學習。不足呢,我覺得他對一些代碼沒有标明用途,希望以後可以多一些用途注釋。
結對照片:
展示PSP:
PSP2.1 | Personal Software Process Stages | Time Senior Student | Time |
Planning | 計劃 | 15 | 22 |
· Estimate | 估計這個任務需要多少時間 | ||
Development | 開發 | 562 | 544 |
·Analysis | 需求分析 (包括學習新技術) | 40 | 35 |
· Design Spec | 生成設計文檔 | 30 | 25 |
· Design Review | 設計複審 | 23 | |
· Coding Standard | 代碼規範 | 10 | |
· Design | 具體設計 | ||
· Coding | 具體編碼 | 240 | 260 |
· Code Review | 代碼複審 | ||
· Test | 測試(自我測試,修改代碼,送出修改) | 50 | |
Reporting | 報告 | 60 | 80 |
測試報告 | 8 | ||
計算工作量 | 12 | ||
并提出過程改進計劃 | 13 |