Which Anti Virus

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Sunday, 1 September 2013

Make Analog Clock using java

Posted on 03:00 by Unknown
write a following code in netbeans IDE 7.1 and save file as Analogclock.java and run it and you will have your own Analog Clock... 

package analogclock;

/**
 *
 * @author NISH
 */
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Calendar;

/*
 <applet code="Clck" width=1500 height=3000>
 </applet>
 */
public class Analogclock extends Applet implements Runnable
{
    private static final double TWO_PI   = 2.0 * Math.PI;
    private Calendar nw = Calendar.getInstance();
    int width=300,hight=300;
    int xcent= width / 2,ycent= hight / 2;
    int minhand,maxhand;
    double rdns;
    int dxmin,dymin,dxmax,dymax;
    double radins,sine,cosine;
    double fminutes;
    Thread t=null;
    Boolean stopFlag;
  
    public void start()
    {
       t=new Thread(this);
       stopFlag = false;
       t.start();
    }
    public void run()
    {
       for( ; ; )
       {
              try {
                     updateTime();
                     repaint();
                     Thread.sleep(100);
                     if(stopFlag)
                        break;
                   }
              catch(InterruptedException e) {}
       }
    }
    public void stop()
    {
        stopFlag=true;
        t=null;
    }
    private void updateTime() {
       
        nw.setTimeInMillis(System.currentTimeMillis());
    }
    public void paint(Graphics g)
    {
        int hours   = nw.get(Calendar.HOUR);
        int minutes = nw.get(Calendar.MINUTE);
        int seconds = nw.get(Calendar.SECOND);
        int millis  = nw.get(Calendar.MILLISECOND);
        minhand=width /8;
        maxhand=width /2;
        rdns= (seconds + ((double)millis/1000)) / 60.0;
        drw(g,rdns,0,maxhand);
        g.drawString(hours + ":" + minutes + ":" + seconds,  minhand+90, maxhand+60);
        minhand = 0;                    // Minute hand starts in middle.
        maxhand = width / 3;
        fminutes = (minutes + rdns) / 60.0;
        drw(g, fminutes, 0, maxhand);
       minhand = 0;                    // Minute hand starts in middle.
        maxhand = width / 4;
        drw(g, (hours + fminutes) / 12.0, 0, maxhand);
        g.drawOval(0,0, width, hight);
        g.drawString("9", xcent-145, ycent -0);
        g.drawString("3", xcent+140, ycent -0);
        g.drawString("6",xcent , ycent+145);
        g.drawString("12",xcent , ycent-135);
     }
   
    public void drw(Graphics g,double prct,int minRadius, int maxRadius) 
    {
        radins= (0.5 - prct)* TWO_PI;
        sine   = Math.sin(radins);
        cosine = Math.cos(radins);
        dxmin = xcent + (int)(minRadius * sine);
        dymin = ycent + (int)(minRadius * cosine);
       
        dxmax = xcent + (int)(maxRadius * sine);
        dymax = ycent + (int)(maxRadius * cosine);
      
        g.drawLine(dxmin, dymin, dxmax, dymax);
    }
   

}

output:-

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in java | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • GTU Paper Solution and Material as Per GTU syllabus
    Go to this website and download the Study material of GTU Syllabus. http://gtu-paper.blogspot.com/
  • How to read the barcodes???
    Trick to read the barcodes The first 3 digits of the barcode is the country code wherein the product was made. CODE COUNTRY 00-13 USA & ...
  • Different Types Of Computer Ports
  • Features Of Android KitKat
    1) The new Phone (Dialer) app is now linked online with Google Maps. This means if your type Big Bazaar in Phone app (Not Search) and if tha...
  • Windiows 8 RUN Commands
    Useful windows RUN Commands 1. Accessibility Controls – access.cpl 2. Accessibility Wizard – accwiz 3. Add Hardware Wizard – hdwwiz.cpl 4. A...
  • C Program Library files(Header Files)
    1. <stdio.h>: input and output  function in program. 2. <conio.h>: to clear screen and  pause information function. 3. <ctype...
  • Android Secrete codes
    1. Phone Information, Usage and Battery – *#*#4636#*#* 2. IMEI Number – *#06# 3. Enter Service Menu On Newer Phones – *#0*# 4. Detailed Came...
  • Free Download E-DRAW MAX
    link 1 : http://hotfile.com/dl/ 254163134/8de2252/EDM.rar.html
  • How To Check Antivirus Strength or Test Antivirus Software or Check Antivirus Which is Used by You is Good or Worst?
    One of the most asked question is  Which antivirus has good strength or How to check antivirus strength? This post is for them who want to c...
  • How to make a bootable pendrive using command prompt!!
    1. Type “diskpart” inside the command  prompt and hit “ENTER”. 2. After last step type “list disk” inside the  command prompt and hit “ENTER...

Categories

  • Android
  • Android Apps
  • apps
  • BlackBerry
  • Cprog
  • dfd
  • erd
  • Facebook
  • general
  • Hacking
  • HTC
  • ios
  • java
  • Mobile
  • nokia
  • Samsung
  • Srs
  • Window Apps
  • Windows 8

Blog Archive

  • ▼  2013 (91)
    • ►  November (6)
    • ►  October (5)
    • ▼  September (17)
      • How to Get Maximum Battery Life in Laptop?
      • Android Secrete codes
      • How To recover Saved Password In Firefox ?
      • How To Install Android on PC or Laptop
      • Download Your Torrent Files Using IDM
      • How To Watch or Stream Torrents Without Downloading
      • How Can You Disable Your Desktop?
      • Simple Demo Of RMI Registry Program
      • Steps To Run RMI Program in JAVA
      • To Convert a FAT Partition to NTFS
      • Steps To Delete Viruses From your PenDrive
      • Get to Unblocked Websites Using Google! - Google a...
      • Steps To Find Manufacturing Date Of Your Computer
      • Password Vulnerability in All Browser
      • Lock Your Folder Without Any Software
      • Java Swing Look and Feel Feature-Example-Set Motif...
      • Make Analog Clock using java
    • ►  August (3)
    • ►  July (8)
    • ►  June (13)
    • ►  May (12)
    • ►  April (27)
Powered by Blogger.

About Me

Unknown
View my complete profile