sábado, 6 de julio de 2013

APPLET

INSTRUCCIÓN  APPLET:

EJERCICIO   "1"

RELOJ DIGITAL


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

import java.applet.*;
 import java.awt.*;
 import java.util.*;
 import java.text.DateFormat;


     public class MiApplet extends Applet implements Runnable
 {
    private Thread hilo = null;
    private Font fuente;
    private String horaActual = "00:00:00";

    public void init()
    {
       fuente = new Font("Verdana", Font.BOLD, 24);
    }
    public void start()
    {
       if (hilo == null)
       {
          hilo = new Thread(this, "Reloj");
          hilo.start();
       }
    }
    public void run()
    {
       Thread hiloActual = Thread.currentThread();
       while (hilo == hiloActual)
       {
       
          Calendar cal = Calendar.getInstance();
          Date hora = cal.getTime();
          DateFormat df = DateFormat.getTimeInstance();
          horaActual = df.format(hora);
          repaint();
          try
          {
             Thread.sleep(1000);
          }
          catch (InterruptedException e){}
       }
    }
    public void paint(Graphics g)
    {
   
       g.draw3DRect(1, 1, getSize().width-3, getSize().height-3, false);
   
       g.setFont(fuente);
   
       g.drawString(horaActual,14,40);
    }
    public void stop()
    {
       hilo = null;
    }
 }

No hay comentarios:

Publicar un comentario