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();
				}
			}
		}

	}

程序运行

运行截图展示(部分)

结对过程

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

做一个“汉堡包”

    先来一片面包:队友是一个精力充沛的人,学习能力很不错,对新知识的接受能力非常优秀。

    再把肉放上:但是他在做项目的时候不够冷静,遇到bug老是有点烦躁,这样往往不能解决问题。另外写代码是一件很枯燥的事情,队友总是写了一会儿就想休息,导致延长了项目完成时间。

    然后再来一片面包:如果他在遇到bug是能够静下心来,好好思考或者寻求他人,在做事时有点恒心,一定可以做得更好。

小结感受

    比起组队编程,我更喜欢一个人敲代码,这样可以充分的考虑到各个功能之间的联系。在两个功能交互遇到隐藏极深的bug,并且两个功能分属不同的人做的时候,因为不熟悉对方的功能结构,要找到bug并不容易,这时候如果是同一个人做的话,我觉得OK。但是在现实中一个项目的完成往往离不开团队合作,一个人很难完成所有的工作,就算技术上允许时间上也不允许,毕竟一个人的精力是有限的。当队友水平差不多的时候1+1>2往往是成立的。

PSP

posted on 2017-10-15 23:40  明天开始有梦想  阅读(422)  评论(2编辑  收藏  举报