Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  ClockApplet.java
Language: JAVA
Code:
import java.applet.*;
import java.awt.*;
import java.util.*;

public class ClockApplet extends Applet implements Runnable
{
  Thread t,t1;
  public void start()
{
  t = new Thread(this);
  t.start();
}
  
  public void run()
{
  t1 = Thread.currentThread();
  while(t1 == t)
{
  repaint();
  try
{
  t1.sleep(1000);  
}
catch(InterruptedException e)
{}
}
}

  public void paint(Graphics g)
{

  Calendar cal = new GregorianCalendar();
  String hour = String.valueOf(cal.get(Calendar.HOUR));
  String minute = String.valueOf(cal.get(Calendar.MINUTE));
  String second = String.valueOf(cal.get(Calendar.SECOND));
  g.drawString(hour + ":" + minute + ":" + second, 20, 30);

  Calendar date = new GregorianCalendar();
  String day = String.valueOf(date.DAY_OF_MONTH);
  String month = String.valueOf(date.MONTH);
  String year = String.valueOf(date.YEAR); 
  g.drawString(day + ":" + month + ":" + year, 80,100);

}
}
/*<Applet code="ClockApplet" width=350 height=350>
</Applet>*/


/*


""+day + ":" + month + ":" + year,80,100);*/
Comments: