这是一个Java版的世界时钟示例,移植自Gerrit创建的同名Swing应用(http://www.jug-muenster.de/swing-worldclock-427
),需要运行在JRE1.5或以上环境当中。
移植此示例主要是因为前一阵移植过Gerrit的swing原子钟示例,所谓好事成双,这个世界时钟的示例自然不能放过(话说Gerrit为什么那么喜欢做时钟?……),毕竟Java桌面应用实例本就不多,但凡有参考价值的还是要多做汇总才好。
另外,此示例中关于多时区的分辨与显示部分,在非桌面应用中也具备一定的参考价值。
PS:由于此示例以LGame-Simple-0.2.5开发,所以也可以看作是世界时钟的AWT实现。
下载地址(源码在jar中):http://loon-simple.googlecode.com/files/WorldClock.7z
运行代码如下所示(构建过程省略了Swing原版的一些步骤):
package org.loon.test;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import org.loon.framework.game.simple.GameScene;
import org.loon.framework.game.simple.core.graphics.Deploy;
import org.loon.framework.game.simple.core.graphics.Screen;
import org.loon.framework.game.simple.utils.GraphicsUtils;
/**
* Copyright 2008 - 2009
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* @project loonframework
* @author chenpeng
* @email:ceponline@yahoo.com.cn
* @version 0.1
*/
public class Main extends Screen {
// 此示例移植自http://www.jug-muenster.de/swing-worldclock-427/同名应用
public Main() {
// 设置窗体背景
this.setBackground(createBackgroundImage());
// 创建时间精灵