date problem... help please...!!!!!!!!!!!
here is that date component code
import java.util.*;
import java.util.Date;
import java.util.GregorianCalendar;
public class MarqueeString extends Thread
{
Date date;
GregorianCalendar calendar;
String strdate,strtime,strstatus;
Thread th;
public MarqueeString()
{
th = new Thread(this);
th.start();
}
public void run()
{
while (th != null)
{
display();
try
{
th.sleep(1000);
}
catch (Exception exception)
{
}
}
}
public String display()
{
date = new Date();
calendar = new GregorianCalendar();
calendar.setTime(date);
strtime = calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.YEAR);
return strtime;
}
};
and in this file i'm using it
/*<applet code="ex_marquee.class" height="400" width="500"></applet>*/
import java.awt.*;
import javax.swing.*;
public class ex_marquee extends JApplet implements Runnable
{
JPanel main_pn,pn;
JLabel lbl;
MarqueeString marc_;
public void init()
{
main_pn = new JPanel();
getContentPane().add(main_pn);
main_pn.setBackground(new Color(0xfffffff));
marc_ = new MarqueeString();
marc_.start();
lbl = new JLabel(marc_.display());
main_pn.add(lbl);
}
public void run()
{
main_pn.add(lbl);
}
}
thanks in advance
sorry for this,
as you have gone through code, here is its description.
the first part of the code is a date compontent, which I want to reuse it in my other application also.
And in second part I am using this component in JLabel to display the time.
It is showing the time but the problem is that it does not in loop, i.e its show time only once when the applet start, its not in Runnable state
tell me please, what i have done wrong...
sorry for this,
as you have gone through code, here is its description.
In first part of the code is a date compontent, which I want to reuse it in my other application also.
And in second part I am using this component in JLabel to display the time.
It is showing the time but the problem is that it does not in loop, i.e its show time only once when the applet start, its not in Runnable state
tell me please, what i have done wrong...
> thanks , I will try to do it using Timer class.
> but I want to know that why its not
> displayIng the desired output which, I want. What
> wrong with this code.
For one thing, look at the "display" method. Does it actually "display" anything? No, it just returns a String representing the current date/time. You have to put that String somewhere to be displayed.
Ok, you are (kind of) - when you create the JLabel. But that only sets the label's text ONCE. You have to keep adjusting the label's text somewhere, it's not going to do it by magic.