public static void main(String[] args) { ClockDisplay cd1 = new ClockDisplay(9, 35); int i = 0; while (i < 10) { System.out.println(cd1.getTime()); cd1.timeTick(); i++; } }
private void start() { synchronized (clockDisplay) { if (start) { label.setText(clockDisplay.refresh()); } else { try { System.out.println("µÈ´ýÖÐ"); clockDisplay.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } }
private void command(String type) { synchronized (clockDisplay) { if (type.equalsIgnoreCase("start")) // Æô¶¯ { start = true; if (!hasStart) { t = new Thread(this); hasStart = true; t.start(); } clockDisplay.notify(); } else if (type.equalsIgnoreCase("clear")) // ÔÝÍ£ { start = false; clockDisplay.clear(); label.setText(clockDisplay.toString()); } else { start = false; } } }