Analog clock

Analog clock

how to develope analog clock using java?

View Answers

June 10, 2011 at 1:30 PM

001 import java.awt.*;

002 import java.applet.*;

003 import java.util.Date;

004

005 public class ac extends Applet implements Runnable

006 {

007 Graphics og;

008 Image oi;

009 Thread t = null;

010 int width, height, delay = 500;

011

012 Date currTime;

013 int timeH, timeM, timeS, radius = 50, lenH, lenM, lenS,

014 lenIn, cx, cy, x1, y1, x2, y2;

015

016 public void init()

017 {

018 super.init();

019 width = size().width;

020 height = size().height;

021 resize(width, height);

022

023 lenH = 5 * radius / 10;

024 lenM = 6 * radius / 10;

025 lenS = 7 * radius / 10;

026 lenIn = 8 * radius / 10;

027 cx = width / 2;

028 cy = height / 2;

029

030 oi = createImage(width, height);

031 og = oi.getGraphics();

032 }

033

034 public void start()

035 {

036 if (t == null)

037 {

038 t = new Thread(this);

039 t.start();

040 }

041 }

042

043 public void stop()

044 {

045 t.stop();

046 t = null;

047 }

048

049 public void run()

050 {

051 Thread.currentThread().setPriority(Thread.NORM_PRIORITY - 1);

052 while (true)

053 {

054 repaint();

055 try

056 {

057 Thread.sleep(delay);

058 }

059 catch (InterruptedException e) {}

060 }

061 }

062

063 public void update(Graphics g)

064 {

065 paint(g);

066 }

067

068 public void paint(Graphics g)

069 {

070 og.setColor(new Color(170, 170, 170));

071 og.fillRect(0, 0, width, height);

072 currTime = new Date();

073 timeH = currTime.getHours();

074 timeM = currTime.getMinutes();

075 timeS = currTime.getSeconds();

076

077 if (timeH >= 12)

078 timeH -= 12;

079

080 for (int i = 1; i < 13; i++)

081 {

082 og.setColor(new Color(20, 20, 20));

083 x2 = (int)(cx + radius * Math.sin(i * 2 * 3.14159f / 12));

084 y2 = (int)(cy - radius * Math.cos(i * 2 * 3.14159f / 12));

085 if (i % 3 != 0)

086 {

087 x1 = (int)(cx + 0.9f * radius * Math.sin(i * 2 * 3.14159f / 12));

088 y1 = (int)(cy - 0.9f * radius * Math.cos(i * 2 * 3.14159f / 12));

089 }

090 else

091 {

092 x1 = (int)(cx + 0.8f * radius * Math.sin(i * 2 * 3.14159f / 12));

093 y1 = (int)(cy - 0.8f * radius * Math.cos(i * 2 * 3.14159f / 12));

094 }

095 og.drawLine(x1, y1, x2, y2);

096 og.setColor(new Color(230, 230, 230));

097 og.drawLine(x1 - 1, y1 - 1, x2 - 1, y2 - 1); 098 }

099 og.setColor(new Color(20, 20, 20));

100 x2 = (int)(cx + lenH * Math.sin((timeH + timeM / 60.0f + timeS / 3600.0f)

101 * 2 * 3.14159f / 12));

102 y2 = (int)(cy - lenH * Math.cos((timeH + timeM / 60.0f + timeS / 3600.0f)

103 * 2 * 3.14159f / 12));

104 og.drawLine(cx, cy, x2, y2);

105 og.setColor(Color.red);

106 og.drawLine(cx - 1, cy - 1, x2 - 1, y2 - 1);

107 108 og.setColor(new Color(20, 20, 20));

109 x2 = (int)(cx + lenM * Math.sin((timeM + timeS / 60.0f) * 2 * 3.14159f / 60));

110 y2 = (int)(cy - lenM * Math.cos((timeM + timeS / 60.0f) * 2 * 3.14159f / 60));

111 og.drawLine(cx, cy, x2, y2);

112 og.setColor(Color.green);

113 og.drawLine(cx - 1, cy - 1, x2 - 1, y2 - 1); 114

115 og.setColor(new Color(20, 20, 20));

116 x2 = (int)(cx + lenS * Math.sin(timeS * 2 * 3.14159f / 60));

117 y2 = (int)(cy - lenS * Math.cos(timeS * 2 * 3.14159f / 60));

118 og.drawLine(cx, cy, x2, y2);

119 og.setColor(Color.blue);

120 og.drawLine(cx - 1, cy - 1, x2 - 1, y2 - 1);

121

122 og.setColor(new Color(20, 20, 20));

123 og.drawOval((width - 2 * radius) / 2, (height - 2 * radius) / 2, 2 * radius,

124 2 * radius);

125 og.setColor(new Color(230, 230, 230));

126 og.drawOval((width - 2 * radius) / 2 - 1, (height - 2 * radius) / 2 - 1,

127 2 * radius, 2 * radius);

128

129 g.drawImage(oi, 0, 0, this);

130 }

131 }

source code for the analog clock < applet code=ac.class width=120 height=120>

HTML example for the analog clock









Related Tutorials/Questions & Answers:
Analog clock
Analog clock  how to develope analog clock using java
analog to digital
analog to digital  how to convert analog to digital in java ?   Hi, What is to be converted? Is it sound or video?ADS_TO_REPLACE_1 Thanks
Advertisements
ModuleNotFoundError: No module named 'analog'
ModuleNotFoundError: No module named 'analog'  Hi, My Python... 'analog' How to remove the ModuleNotFoundError: No module named 'analog'... to install padas library. You can install analog python with following command
ModuleNotFoundError: No module named 'django-analog'
ModuleNotFoundError: No module named 'django-analog'  Hi, My... 'django-analog' How to remove the ModuleNotFoundError: No module named 'django-analog' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-analog'
ModuleNotFoundError: No module named 'django-analog'  Hi, My... 'django-analog' How to remove the ModuleNotFoundError: No module named 'django-analog' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'signal-analog'
ModuleNotFoundError: No module named 'signal-analog'  Hi, My... 'signal-analog' How to remove the ModuleNotFoundError: No module named 'signal-analog' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-analog'
ModuleNotFoundError: No module named 'django-analog'  Hi, My... 'django-analog' How to remove the ModuleNotFoundError: No module named 'django-analog' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'clock'
ModuleNotFoundError: No module named 'clock'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'clock' How to remove the ModuleNotFoundError: No module named 'clock'
ModuleNotFoundError: No module named 'clock'
ModuleNotFoundError: No module named 'clock'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'clock' How to remove the ModuleNotFoundError: No module named 'clock'
ModuleNotFoundError: No module named 'clock'
ModuleNotFoundError: No module named 'clock'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'clock' How to remove the ModuleNotFoundError: No module named 'clock'
ModuleNotFoundError: No module named 'my_clock'
ModuleNotFoundError: No module named 'my_clock'  Hi, My Python..._clock' How to remove the ModuleNotFoundError: No module named 'my_clock... to install padas library. You can install my_clock python with following
ModuleNotFoundError: No module named 'my_clock'
ModuleNotFoundError: No module named 'my_clock'  Hi, My Python..._clock' How to remove the ModuleNotFoundError: No module named 'my_clock... to install padas library. You can install my_clock python with following
ModuleNotFoundError: No module named 'my_clock'
ModuleNotFoundError: No module named 'my_clock'  Hi, My Python..._clock' How to remove the ModuleNotFoundError: No module named 'my_clock... to install padas library. You can install my_clock python with following
ModuleNotFoundError: No module named 'tomato-clock'
ModuleNotFoundError: No module named 'tomato-clock'  Hi, My Python... 'tomato-clock' How to remove the ModuleNotFoundError: No module named 'tomato-clock' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'tomato-clock'
ModuleNotFoundError: No module named 'tomato-clock'  Hi, My Python... 'tomato-clock' How to remove the ModuleNotFoundError: No module named 'tomato-clock' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'binary_clock'
ModuleNotFoundError: No module named 'binary_clock'  Hi, My Python... 'binary_clock' How to remove the ModuleNotFoundError: No module named 'binary_clock' error? Thanks   Hi, In your python
Version of com.statemachinesystems>mock-clock dependency
List of Version of com.statemachinesystems>mock-clock dependency
JavaScript Clock Timer
JavaScript Clock Timer...; In this section, we are going to show you a clock timer using JavaScript...;h2>Clock Timer</h2> <script language="JavaScript" type="text
ModuleNotFoundError: No module named 'real-time-analog-monitoring-tool'
ModuleNotFoundError: No module named 'real-time-analog-monitoring-tool' ...: ModuleNotFoundError: No module named 'real-time-analog-monitoring-tool' How to remove the ModuleNotFoundError: No module named 'real-time-analog-monitoring-tool'
ModuleNotFoundError: No module named 'Async-Exec-Clock'
ModuleNotFoundError: No module named 'Async-Exec-Clock'  Hi, My... named 'Async-Exec-Clock' How to remove the ModuleNotFoundError: No module named 'Async-Exec-Clock' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'ethereum-alarm-clock-client'
ModuleNotFoundError: No module named 'ethereum-alarm-clock-client'  ...: No module named 'ethereum-alarm-clock-client' How to remove the ModuleNotFoundError: No module named 'ethereum-alarm-clock-client' error? Thanks
ModuleNotFoundError: No module named 'Terminal-Digital-Clock'
ModuleNotFoundError: No module named 'Terminal-Digital-Clock'  Hi...: No module named 'Terminal-Digital-Clock' How to remove the ModuleNotFoundError: No module named 'Terminal-Digital-Clock' error? Thanks   Hi
ModuleNotFoundError: No module named 'Async-Exec-Clock'
ModuleNotFoundError: No module named 'Async-Exec-Clock'  Hi, My... named 'Async-Exec-Clock' How to remove the ModuleNotFoundError: No module named 'Async-Exec-Clock' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'ethereum-alarm-clock-client'
ModuleNotFoundError: No module named 'ethereum-alarm-clock-client'  ...: No module named 'ethereum-alarm-clock-client' How to remove the ModuleNotFoundError: No module named 'ethereum-alarm-clock-client' error? Thanks
Maven Dependency mock-clock >> 1.0
You should include the dependency code given in this page to add Maven Dependency of com.statemachinesystems >> mock-clock version1.0 in your project
Clock Applet in Java
Java - Clock Applet in Java       Introduction Here is a sample of running clock provided by the java applet to illustrate how to use the clock in an applet. This program shows
how can create clock baisc in java
how can create clock baisc in java   think u for help me ..  ...()); content.add(timeField); setTitle("Clock"); setSize(100,70...) { JFrame clock = new DisplayClock(); clock.setVisible(true
how can create clock baisc in java
how can create clock baisc in java   think u for help me ..  ...()); content.add(timeField); setTitle("Clock"); setSize(100,70...) { JFrame clock = new DisplayClock(); clock.setVisible(true
how can create clock baisc in java
how can create clock baisc in java   think u for help me ..  ...()); content.add(timeField); setTitle("Clock"); setSize(100,70...) { JFrame clock = new DisplayClock(); clock.setVisible(true
Maven Repository/Dependency: com.statemachinesystems | mock-clock
Maven Repository/Dependency of Group ID com.statemachinesystems and Artifact ID mock-clock. Latest version of com.statemachinesystems:mock-clock dependencies. # Version Release Date You
How to display mysql database records as per clock timing?
How to display mysql database records as per clock timing?  I want to display database records as per clock timing
Display PHP clock with user input date and time
Display PHP clock with user input date and time  The following PHP code displays a clock with current date and time. I want the clock to receive user input date and time. How can this be done? <?php date<em>
how to build a colorful clock in JSP without using Flash.
how to build a colorful clock in JSP without using Flash.  I have to make a colorful clock using java programming or some API in a JSP page. Please send me a code for it as soon as possible
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for mock-clock version 1.0
Maven, Gradle, SBT, Ivy, Grape, Leiningen and Buildr Dependency for mock-clock... com.statemachinesystems:mock-clock:1.0 Java library in your project.. Maven, Gradle, SBT, Ivy, Grape, Leiningen and  Buildr Dependency for mock-clock version 1.0
java code digital clock - Java Beginners
Time Tracker
Time Tracker       Time Tracker is a simple tool to keep track of the time you spend on any task. Think of it as a to-do-list with a clock. And yes, it's free. Read full Description ADS
How Voice over Internet Protocol (VoIP) Works
protocol work that it is an advance technology that converts the analog audio... that uses "Internet protocol" instead of traditional analog systems. In this technology, analog voice calls are converted into small discrete packets
VoIP Equipment
converts analog voice signals to data and vice-versa so you can speak to anyone... on the Netopia Analog Telephone Adapter (ATA), this distributed solution enables
VoIP Adapters
; VoIP Analog Telephone adapter Inexpensive, easy-to-install...) port for connection to existing analog phones, fax machines, PBX and key... next generation VoIP analog telephone adaptor based on industry open standards
PLease reply its urgent
the number of times the minute and hour hands of a standard analog clock would cross in that period of time, assuming that the clock always starts at midnight... the signature ΓΆβ?¬Ε?Public static int clock Inter sections(int hours, int minutes)ΓΆβ?¬Β
OOP - Java Beginners
a client program for the class clock that creates an array of Clock objects...); public static void main(String[]args) { Clock myClock[]=new Clock[4]; int y=myClock.getTime(); myClock.printTime(); } } public class Clock
Java - Swing AWT
Java  write an application program to show an animation with a single line,which changes its position in a clock-wise and anti clock-wise direction.This line should produce an effect of a spinning line
java - Java Beginners
java  write main method for display clock applet including html source code
What is AMPS?
What is AMPS?   HII, What is AMPS?   Hello,ADS_TO_REPLACE_1 AMPS stands for Advanced Mobile Phone Service. It is a first-generation analog, circuit-switched cellular phone network
OOP using Java - Java Beginners
the object mysteryClock of the Clock type, and initialize the instance variables hr,min...; Hi friend, Code to solve the problem : class Clock { int hr...(String[] args) { Clock mysteryClock = new Clock(); mysteryClock.hr=7
digital diary
digital diary  please post the code for a simple digital diary... with contacts storing facility, passwords , notes, alarm clock and calender
digital diary
digital diary  please post the code for a simple digital diary... with contacts storing facility, passwords , notes, alarm clock and calender
digital diary
digital diary  please post the code for a simple digital diary... with contacts storing facility, passwords , notes, alarm clock and calender
DSL Filter
device. DSL filter, also known as micro filter is an analog low-pass filter device that installs on telephone and other analog device for preventing interference between analog devices and DSL service operating on the same line. DSL filters
closing connections in finally block
closing connections in finally block  Hi, What will happen if I close connection before closing the resultset in the finally clock? e.g. finally... { ... conn.close(); rs.Close(); } If i do as above ... what will happen

Ads