■ 事例

 ↑ TOP

    
tips320_Timer/java/src/AppWindow.java
1: /* 2: * Copyright (c) 2010-2013, KOTSUBU-chan and/or its affiliates. 3: * Copyright (c) 1998, Atelier-AYA. 4: * All rights reserved. 5: */ 6: package cherry.pie; 7: 8: import java.awt.*; 9: import java.text.*; 10: import java.util.*; 11: import javax.swing.*; 12: import javax.swing.Timer; 13: 14: // ---------------------------------------- 15: public class AppWindow extends JFrame { 16: static String version = AppWindow 17: .class.getName() + ": #1.0.01 a"; 18: // ---------------------------------------- 19: static void example() { 20: JFrame frame = new AppWindow("Clock"); 21: frame.add(new View()); 22: frame.pack(); 23: frame.setVisible(true); 24: } 25: 26: // ---------------------------------------- 27: public AppWindow(String title) { 28: super(title); 29: setLocationRelativeTo(null); 30: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 31: } 32: } 33: 34: // ---------------------------------------- 35: class View extends JLabel { 36: public View() { 37: setFont(new Font("Courier", Font.BOLD, 36)); 38: setText("00:00:00"); 39: new Timer(1000, new ActionPerformed() { 40: public void execute() { update(); } 41: }).start(); 42: } 43: public void update() { 44: Date time = Calendar.getInstance().getTime(); 45: setText(new SimpleDateFormat("HH:mm:ss").format(time)); 46: } 47: }

 ↑ UP