¿Cómo escribir un programa de cuenta regresiva de 10 minutos en JAVA?
importar java.awt.Color;
importar java.util.*;
importar java.awt.*;
importar java.applet.*;
Clase pública Reloj extiende Applet implementa Runnable
{
Thread timer=null;
Etiqueta etiqueta;
int lastxs=50,lastys=30,lastxm=50,lastym=30,lastxh=50,lastyh=30;
public void init()
{
etiqueta=nueva etiqueta(" ");
setBackground(Color.white);
agregar(etiqueta);
}
pintura vacía pública (Gráficos g)
{
int xh,yh,xm,ym,xs,ys,s,m,h, xcenter,ycenter;
Fecha ahora mismo=nueva fecha();
Cadena hoy=rightnow.toLocaleString();
etiqueta.setText(hoy);
s=rightnow.getSeconds();
m=rightnow.getMinutes();
h=rightnow.getHours();
xcenter=100;
ycenter=80;
xs=(int)(Math.cos(s*3.14f/30-3.14f/2)*45+xcenter) ;
ys=(int)(Math.sin(s*3.14f/30-3.14f/2)*45+ycenter);
xm=(int)(Matemáticas .cos(m*3.14f/30-3.14f/2)*45+xcenter);
ym=(int)(Math.sin(m*3.14f/30-3.14f/2) *45+ycenter);
xh=(int)(Math.cos((h*3m*2)*3.14f/180-3.14f/2)*3xcenter);
yh=(int)(Math.sin((h*3m*2)*3.14f/180-3.14f/2)*3ycenter);
g .setFont(new Font("TimesToman",Font.PLAIN,14));
g.setColor(Color.orange);
g.fill3DRect(xcenter-50,ycenter -50,100,100,true);
g.setColor(Color.darkGray);
g.drawString("12",xcenter-5,ycenter-37);
g.drawString("3",xcenter+40,ycenter+3);
g.drawString("6",xcenter-3,ycenter+45)
;
g.drawString("9",xcenter-45,ycenter+3);
g.setColor(Color.orange);
if( xs!=lastxs||ys!=lastys)
{
g.drawLine(xcenter,ycenter,lastxs,lastys);
}
if(xm!=lastxm||ym!=lastym)
{
g.drawLine(xcenter,ycenter-1,lastxm,lastym);
g.drawLine(xcenter-1,ycenter,lastxm,lastym);
}
if(xh!=lastxh||yh!=lastyh)
{
g.drawLine(xcenter,ycenter-1,lastxh,lastyh);
g.drawLine(xcenter-1,ycenter,lastxh,lastyh);
}
g.setColor(Color.rojo);
g.drawLine(xcenter,ycenter,xs,ys);
g.drawLine(xcenter,ycenter-1,xm,ym);
g.drawLine(xcenter-1,ycenter,xm,ym);
g.drawLine(xcenter, ycenter-1,xh,yh);
g.drawLine(xcenter-1,ycenter,xh,yh);
lastxs=xs;
lastys =ys;
lastxm=xm;
lastym=ym;
lastxh=xh;
lastyh=yh;
}
inicio vacío público()
{
if(timer==null)
{
temporizador=nuevo hilo(este);
timer.start();
}
}
vacío público stop()
{
timer=null;
}
public void run()
{
while(timer!=null)
{
intentar
{
Thread.sleep(1000 );
}catch(InterruptedException es decir){}
repaint();
}
timer=null;
}
actualización de vacío público (Gráficos g)
{
pintura(g);
}
}