四则运算GUI

by: 201421122071 & 20142122086

Coding地址:(https://git.coding.net/z404395979/GUI-JAVA.git)

需求分析

  1. 有计时功能,能显示用户开始答题后的消耗时间。当用户点击开始答题,计时器开始计时,当用户答题结束,计时器停止计时。

  2. 界面支持中文简体/中文繁体/英语,用户可以选择一种。用户设置语言,开始答题时除数字和符号外其余文字都应变成用户所选语言。

程序设计

TiaoZhuan类:

    页面跳转时的界面语言问题,当语言为中文时设置下个页面为中文。

TimeCount类:

    showTime方法:点击开始按钮开始计时并生成第一道题

    showCount方法:检查输入答案正确性;生成下一道题;保存答题统计。

代码展示

计时器代码:

    /**
     * 计时
     * @param event
     * @throws IOException
     */
    public void showTime(ActionEvent event) throws IOException {
        // System.out.println(programStart);
        programStart = System.currentTimeMillis();
        thread.start();
        thread.stopped = false;
        OpUtil.deleteFile();
        OpUtil.makeFourOp(count, k);
        lab4.setText(Constants.EQUATION);
        btn4.setVisible(false);
        btn5.setVisible(true);
        lab4.setVisible(true);
        textfield3.setVisible(true);
    }

    public boolean stopped = true;

    private CountingThread() {
        setDaemon(true);// 守护线程
    }

    @Override
    public void run() {
        while (true) {
            if (!stopped) {
                long elapsed = System.currentTimeMillis() - programStart;
                    
                String s = format(elapsed);
                    
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        // 更新JavaFX的主线程的代码放在此处
                        label1.setText(s);
                    }
                });

            }

            try {
                sleep(1); // 1毫秒更新一次显示
            } catch (InterruptedException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }

界面语言代码:

@SuppressWarnings("restriction")
    public void tiaoZhuan(ActionEvent event) {
        // System.out.println(programStart);
        System.out.println(Constants.LANGUAGE);
        String str1 = textfield1.getText();
        int count = 0;
        String str2 = textfield2.getText();
        int c = 0;
        if (str1 == null || "".equals(str1.trim()) || !isInteger(str1)) {
            if ("zh_CN".equals(Constants.LANGUAGE)) {
                label5.setText("ERROR:请输入整数");
            } else if ("zh_TW".equals(Constants.LANGUAGE)) {
                label5.setText("ERROR:請輸入整數");
            } else {
                label5.setText("ERROR:please enter an integer");
            }
            label5.setVisible(true);
        } else {
            count = Integer.parseInt(str1);
            System.out.println(count);
            if (count <= 0) {
                if ("zh_CN".equals(Constants.LANGUAGE)) {
                    label5.setText("ERROR:请输入一个大于0的数");
                } else if ("zh_TW".equals(Constants.LANGUAGE)) {
                    label5.setText("ERROR:請輸入一個大於0的數");
                } else {
                    label5.setText("ERROR:Please enter a number greater than 0");
                }
                label5.setVisible(true);
            } else {
                Constants.COUNT = count;
                label5.setVisible(false);
            }
        }

        if (str2 == null || "".equals(str2.trim()) || !isInteger(str2)) {
            if ("zh_CN".equals(Constants.LANGUAGE)) {
                label6.setText("ERROR:请输入整数");
            } else if ("zh_TW".equals(Constants.LANGUAGE)) {
                label6.setText("ERROR:請輸入整數");
            } else {
                label6.setText("ERROR:please enter an integer");
            }
            label6.setVisible(true);
        } else {
            c = Integer.parseInt(str2);
            System.out.println(c);
            if (c <= 0) {
                if ("zh_CN".equals(Constants.LANGUAGE)) {
                    label6.setText("ERROR:请输入一个大于0的数");
                } else if ("zh_TW".equals(Constants.LANGUAGE)) {
                    label6.setText("ERROR:請輸入一個大於0的數");
                } else {
                    label6.setText("ERROR:Please enter a number greater than 0");
                }
                label6.setVisible(true);
            } else {
                Constants.C = c;
                label6.setVisible(false);
                try {
                    ObservableList<Stage> stage = FXRobotHelper.getStages();
                    Scene scene = new Scene(FXMLLoader.load(getClass().getResource("ThirdScene.fxml")));
                    Label lab1 = (Label) scene.lookup("#lab1");
                    Label lab2 = (Label) scene.lookup("#lab2");
                    Label lab3 = (Label) scene.lookup("#lab3");
                    Label lab4 = (Label) scene.lookup("#lab4");
                    Label lab5 = (Label) scene.lookup("#lab5");
                    Button btn4 = (Button) scene.lookup("#btn4");
                    Button btn5 = (Button) scene.lookup("#btn5");
                    TextField textfield3 = (TextField) scene.lookup("#textfield3");
                    if ("zh_CN".equals(Constants.LANGUAGE)) {
                        lab1.setText("请计算每个题目的答案,按回车进入下一题");
                        lab2.setText("(ps:有分数的答案请使用真分数)");
                        lab3.setText("(真分数五分之三表示为3/5,真分数二又八分之三表示为2'3/8。)");
                        btn4.setText("开始");
                        btn5.setText("下一题");
                    } else if ("zh_TW".equals(Constants.LANGUAGE)) {
                        lab1.setText("請計算每個題目的答案,按回車進入下一題");
                        lab2.setText("(ps:有分數的答案請使用真分數)");
                        lab3.setText("(真分數五分之三表示為3/5,真分數二又八分之三表示為2'3/8。)");
                        btn4.setText("開始");
                        btn5.setText("下一題");
                    } else {
                        lab1.setText(
                                "Please calculate the answer to each question and press enter to go to the next question");
                        lab1.setWrapText(true);
                        lab2.setText("(ps:Use the true score for the answer with a score)");
                        lab3.setText("(True fraction 3/5 is 3/5, true fraction two and three eighths is 2'3/8.)");
                        lab3.setWrapText(true);
                        btn4.setText("Begin");
                        btn5.setText("Next");
                    }
                    btn5.setVisible(false);
                    lab5.setVisible(false);
                    lab4.setVisible(false);
                    textfield3.setVisible(false);
                    stage.get(0).setScene(scene);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

    }

程序运行

运行截图展示(部分)

结对过程

    因为是同一个宿舍,自然而然组成一队。

做一个“汉堡包”

  我的队友个人能力比较强,在整个开发过程中引导和帮助我完成这个项目,很积极的将他的思路分享给我,并使我能简单易懂的接受,如果有缺点就是性格倔强,今晚做完就要今晚做完。

小结感受

  结对开发讲究的是两个人的配合,以达到工作中的互相帮助,两个人开发比一个人开发在工作量上肯定是有所减少,但是相对花在熟悉对方代码,进行思维探讨的时间会增多,所以工作效率取决于两个人的熟悉程度和技术水平的高低,如果两个人水平差不多,又互相熟悉,那开发起来自然可以达到1+1>2的效果。

PSP

 

posted on 2017-10-22 21:32  acsec  阅读(241)  评论(1编辑  收藏  举报