Share on Google+Share on Google+

Rashidul Islam Sarkar
Write an Applet which display current date and time on the web page??
1 Answer(s)      4 years and 9 months ago
Posted in : Applet

Write an Applet which display current date and time on the web page??

Ads

View Answers

July 9, 2012 at 2:24 PM


Here is an applet code that display date and time.

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){
  Calendar cal = new GregorianCalendar();
  Date d=cal.getTime();
  SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
  g.drawString(sdf.format(d), 20, 30);
  }
}

To call this applet, you need to create an html file.

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









Related Tutorials/Questions & Answers:
Advertisements
Tutorials   
Java Spring Hibernate Struts Training Error in calling javascript function from java prg Creating an Applet java program Display Java in JSP Draw bufferimage in jpanel using netbeans Moving Applet Problem c programming Attendence Management system java program of different shapes help applet printing p applet dought Help please, some strange errors Write an applet to display scrolling image in an applet window using thread. Simple Java applet that need usernam, password and textfield. conversion Applet java program java program java program scrolling text in applet java java applet java applet project in java using applet and servlet...which tool i should use?eclipse or netbeans? java user input to database user input to database user input to database button to accept user input jframe what is web .config method Can any one please help me in this ,,,,,,, need java code for this ,,,,please anyone applet question Write an Applet which display current date and time on the web page?? Write an Applet which display current date and time on the web page?? Java Applet - Adding a Button to Decrease a Total Applet Application how to drag top most images which is draw on applet. convert java Application to Java Applet convert java Application to Java Applet Problem In applet Its run on browser but hang and blinking when image is draging some where. how to access database in applet How to add dropdown list in a row of a sort table applet? java project topics plz anyone can solve my Layout Manager Project Guidance applet is running but no display

Ads

 
Advertisement null

Ads