Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rohit gangurde
Applent
1 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners


PLEASE i need a program including..... Applet to display clock using simpledateformat calendar and graphic classes...


Advertisement
View Answers

October 14, 2011 at 12:54 PM


1)ClockApplet.java:

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

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){
  SimpleDateFormat sdf=new SimpleDateFormat("HH:mm:ss");
  Date d=new Date();
  String str=sdf.format(d);
  g.drawString(str, 20, 30);

  }
}

2)applet.html:

<HTML>
<BODY>
<div align = "center">
<APPLET CODE = "ClockApplet" WIDTH = "500" HEIGHT = "400"></APPLET>
</div>
</BODY>
</HTML>


Related Tutorials/Questions & Answers:
 

 

 

DMCA.com