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??

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

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:
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??
Advertisements
javascript current date and time.
How to display the current time
Get current Date and Time
Write an applet to display scrolling image in an applet window using thread.
How to display current date in textbox - Date Calendar
Iphone Show Current Date & Time
iPhone Date Picker
Display current time using jQuery & JSP
Display Current Date using JSP Custom(user define) Tag
J2ME Current Date And Time
updated with current date n time
display current time when using datetimepiker in struts2
Mysql Date Arithmetic
date format to be updated with current date time
Write date servlet and test on tomcat
Display Date and Time - Design concepts & design patterns
JDBC: Get current Date and Time Example
how to display(update) current date and month in select box on selecting the year.
How can we get second of the current time using date function?
Display PHP clock with user input date and time
Get Date and Time
Display current time & system properties using JSP expressions
Mysql Date and Time
Write an applet that prints "Lear Java it is useful" at the current cursor position whenever the mouse left button is clicked.
Applet ... - Date Calendar
Mysql Date no Time
PHP Display date and time
Display current date in text box in JSP using javascript
Current Date and Time
Current Date and Time
How to get the current date in Java?
current date set
Display Date - Java Beginners
JDBC : Current Date
convert current date into date format
By using Applet display a circle in a rectangle
Iphone Current Date Application
C Current Time
Mysql Date from Date
Mysql Date Format codes
applet running but no display - Applet
Time display - JSP-Servlet
Current date in php
applet is running but no display
date_time_set
iPhone Current Date, iPhone Current Date Application
Java current date - How to get current date in Java
Date & Time

Ads