Java World Clock example

Source: Internet
Author: User

This is a Java version of The World Clock example, transplanted from Gerrit created by the same name swing application (http://www.jug-muenster.de/swing-worldclock-427
To run in jre1.5 or above.

 

The main reason for porting this example is that the previous example of a swing atomic clock with Gerrit has been transplanted. The so-called "good" is a pair, and the example of a world clock cannot be used. (Why do Gerrit like clock so much ?......), After all, there are not many Java Desktop Application Instances, but any useful examples should be summarized.

 

In addition, the multi-time zone resolution and Display section in this example also has some reference value in non-desktop applications.

 

PS: Since this example is developed in LGame-Simple-0.2.5, it can also be seen as the AWT implementation of the world clock.

 

(Source code in jar): http://loon-simple.googlecode.com/files/WorldClock.7z

 

Run the following code ):

 

Package Org. loon. test; <br/> Import Java. AWT. graphics2d; <br/> Import Java. AWT. event. keyevent; <br/> Import Java. AWT. event. mouseevent; <br/> Import Java. AWT. image. bufferedimage; <br/> Import Org. loon. framework. game. simple. gamescene; <br/> Import Org. loon. framework. game. simple. core. graphics. deploy; <br/> Import Org. loon. framework. game. simple. core. graphics. screen; <br/> Import Org. loon. framework. game. simple. utils. graphicsutils; <br/>/** <br/> * Copyright 2008-2009 <br/> * licensed under the Apache license, version 2.0 (the "License"); you may not <br/> * use this file except T in compliance with the license. you may obtain a copy of <br/> * The license at <br/> * http://www.apache.org/licenses/LICENSE-2.0 <br/> * unless required by applicable law or agreed to in writing, software <br/> * distributed under the license is distributed on an "as is" basis, without <br/> * warranties or conditions of any kind, either express or implied. see the <br/> * license for the specific language governing permissions and limitations under <br/> * the license. <br/> * @ project loonframework <br/> * @ author chenpeng <br/> * @ Email: ceponline@yahoo.com.cn <br/> * @ version 0.1 <br/> */<br/> public class main extends screen {<br/> // This example is transplanted from http://www.jug-muenster.de/swing-worldclock-427/same name application <br/> public main () {<br/> // set the background of the form <br/> This. setbackground (createbackgroundimage (); <br/> // creation time genie <br/> analogclock clock1 = new analogclock (city. beijing, 25, 18, 74, 74); <br/> analogclock clock2 = new analogclock (city. newYork, 25,108, 74, 74); <br/> analogclock clock3 = new analogclock (city. sanfrancisco, 25,198, 74, 74); <br/> analogclock clock4 = new analogclock (city. dakka, 25,288, 74, 74); <br/> // Add genie <br/> This. add (clock1); <br/> This. add (clock2); <br/> This. add (clock3); <br/> This. add (clock4); <br/>}< br/> Public void draw (graphics2d g) {<br/>}< br/>/** <br/> * Create a background pattern <br/> * @ return <br/> */< br/> private bufferedimage createbackgroundimage () {<br/> final Java. AWT. image. bufferedimage image = graphicsutils. createimage (<br/> getwidth (), getheight (), Java. AWT. transparency. translucent); <br/> JAVA. AWT. graphics2d g2 = image. creategraphics (); <br/> g2.setrenderinghint (Java. AWT. renderinghints. key_antialiasing, <br/> JAVA. AWT. renderinghints. value_antialias_on); <br/> JAVA. AWT. geom. point2d background_start = new Java. AWT. geom. point2d. double (<br/> 0, 0); <br/> JAVA. AWT. geom. point2d background_stop = new Java. AWT. geom. point2d. double (<br/> 0, getheight (); <br/> final float [] background_fractions = {0.0f, 1.0f}; <br/> final Java. AWT. color [] background_colors = {<br/> New Java. AWT. color (0x505652), new Java. AWT. color (0x393e3a) }; <br/> final Java. AWT. shape background = new Java. AWT. geom. roundrectangle2d. double (<br/> 0, 0, getwidth (), getheight (), 5, 5); <br/> final Java. AWT. lineargradientpaint background_gradient = new Java. AWT. lineargradientpaint (<br/> background_start, background_stop, background_fractions, <br/> background_colors); <br/> g2.setpaint (background); <br/> g2.fill (background ); <br/> JAVA. AWT. geom. point2d inner_background_start = new Java. AWT. geom. point2d. double (<br/> 0, 10); <br/> JAVA. AWT. geom. point2d inner_background_stop = new Java. AWT. geom. point2d. double (<br/> 0, getheight ()-10); <br/> final float [] inner_background_fractions = {0.0f, 1.0f}; <br/> final Java. AWT. color [] inner_background_colors = {<br/> New Java. AWT. color (0x4d5651), new Java. AWT. color (0x393e3a) }; <br/> final Java. AWT. shape inner_background = new Java. AWT. geom. roundrectangle2d. double (<br/> 10, 10, getwidth ()-20, getheight ()-20, 5, 5); <br/> final Java. AWT. lineargradientpaint inner_background_gradient = new Java. AWT. lineargradientpaint (<br/> inner_background_start, inner_background_stop, <br/> temperature, temperature); <br/> g2.setpaint (temperature); <br/> g2.fill (inner_background ); <br/> g2.setcolor (New Java. AWT. color (0x2f362e); <br/> g2.drawline (10, 10, getheight ()-10); <br/> g2.drawline (getwidth ()-10, 10, getwidth ()-10, getheight ()-10); <br/> g2.drawline (10, 10, getwidth ()-10, 10 ); <br/> g2.setcolor (New Java. AWT. color (0x6b7167); <br/> g2.drawline (10, getheight ()-10, getwidth ()-10, getheight ()-10 ); <br/> g2.dispose (); <br/> return image; <br/>}< br/> Public void leftclick (mouseevent E) {<br/>}< br/> Public void middleclick (mouseevent e) {<br/>}< br/> Public void rightclick (mouseevent E) {<br/>}< br/> Public void onkey (keyevent e) {<br/>}< br/> Public void onkeyup (keyevent E) {<br/>}< br/> Public static void main (string [] ARGs) {<br/> gamescene frame = new gamescene ("world clock for Java ", (398,391); <br/> deploy = frame. getdeploy (); <br/> deploy. setscreen (New Main (); <br/> deploy. setshowfps (true); <br/> deploy. setlogo (false); <br/> deploy. setfps (100); <br/> deploy. mainloop (); <br/> frame. showframe (); <br/>}< br/>


The running effect is as follows:

 

 

 

 

(The source code is in jar)

: Http://loon-simple.googlecode.com/files/WorldClock.7z

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.