/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
import javax.swing.*;
import java.io.*;
import java.applet.AppletContext;
import java.awt.Canvas;
import java.applet.Applet;
import java.awt.Image;
import java.lang.Math;
import java.util.Calendar;
import java.util.Random;


/**
 *
 * @author dario
 */
public class contador extends JApplet implements Runnable, MouseMotionListener {

   int mx, my;
   Point[] points;
   int N = 300;

   Image fundo = null;
   Image logo = null;

    Timer conta;
    Thread tela;
    int d=360, h=360, m=360, s=360, fim=0;
    int dia=30;

    public void init() {        
      setBackground( Color.ORANGE );
      setSize(150, 180);
      fundo = getImage(getCodeBase(), "ImagemContador.jpg");
      setSize(110, 120);
      logo= getImage(getCodeBase(), "logo_ubuntuTransp.gif");

      addMouseMotionListener( this );
    }

    public void start(){
        tela = new Thread(this);
        tela.start();
    }

    public void run(){
        while(true){
            if(dia!=0){
            if(h==0){
                dia--;
                h = 360;
                d=d-12;
            }
            if(m<=0){
                m = 360;
                h=h-6;
            }
            if(s<=0){
                s = 360;
                m=m-6;
            }
            else
                s=s-6;            
            }
            try{Thread.sleep(987);}catch(Exception exc){}
            repaint();
        }
    }

    public void stop(){
    }

    public void destroy(){

    }

    public void paint(Graphics g)  {
        g.drawImage(fundo, 0, 0, this);
        if(dia!=0){
            g.drawImage(logo, 32, 20, this);
            g.setColor(Color.GREEN);
            g.fillArc(50, 30, 100, 100, 0, d);
            g.setColor(Color.RED);
            g.fillArc(60, 40, 80, 80, 0, h);
            g.setColor(Color.YELLOW);
            g.fillArc(70, 50, 60, 60, 0, m);
            g.setColor(Color.BLUE);
            g.fillArc(80, 60, 40, 40, 0, s);
            g.setColor(Color.BLACK);
             g.drawString(dia+"", 90, 84);
        }
        else
            g.drawImage(logo, 32, 20, this);
        g.drawString(Mensagem(), 4, 14);       
    }

    public String Mensagem(){
        if(dia==0){
            return "Ubuntu 11.04";
        }
        else{
            if(dia>10)
                return "days left";
            else
                return "coming soon...";
        }
    }

    public boolean mouseMove(Event e, int x, int y ) {
        return true;
    }

     public boolean mouseDown(Event e, int x, int y ) {
         return true;
     }

     public void mouseMoved( MouseEvent e ) {
      mx = e.getX();
      my = e.getY();
   }
   public void mouseDragged( MouseEvent e ) { }


    public static void main(String[] args) {
    }

}
