• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display date and time using applet and threads concept  RSS feed

 
Jdinesh Tiwari
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//Modify the class declarations.Please note where ever declarations are
//specified they are depicted by ... and modifications or additions to
//code are made in bold.

//Add the following import statements
import java.util.Date;
import java.util.Calander;
import java.util.GregorianCalendar;

public class InterviewerApplet extends JApplet implements Runnable

{
Declare pannels
...
Declare buttons
...
Declare txetfields
...
Declare textArea
...
Thread datimeThread;

//Declare a date variable

Date date;

//Declare a GregorianCalandar variable
GregorianCalendar calendar;
//Declare String variable to store date,
//time and status bar messages
String strdate, strTime, strStatus;
//init method of applet
public void init()
{
...
createAppletContent();
}
protected void createAppletContent()
{
candidateDetail();
}
public void candidateDetail()
{
...
...
datimeThread = new Thread(this)
// Initialize thread
datimeThread.start();//starting thread
}
public void run()
{
while(datimeThread !=null)
{
display();//This method displays date
try
{
datimeThread.sleep(1000);
}
catch(InterruptedException e)
{
showStatus("Thread interrupted");
}
}//end of while
}//end of run
public void display()
{
date = new Date();
calendar = new GregorianCalendar();
strTime = calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(calendar.SECONDS);
strDate = calendar.get(calendar.MONTH)+"/"+calendar.get(calendar.DATE)+"/"+calendar.get(calendar.YEAR);
strStatus = strTime+" "strDate;
showStatus(strStatus);
}
public void testDetail()
{
....//test details code
}
}//end of program

Hi all it was to incorporate this code using applet and and using threads concepts to display date and time
may help on the same

Thanks




 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!