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

[1589 byte] By [logictrenda] at [2007-11-26 21:05:40]
# 1
Not a very good description of a problem nor a question at all.Is someone here supposed to read your mind for the rest of the context of that post?
warnerjaa at 2007-7-10 2:39:28 > top of Java-index,Java Essentials,New To Java...
# 2
> Is someone here supposed to read your mind for the> rest of the context of that post?Oooooom.......ooooooooom.......I'm getting nothing, just black emptiness.
Djaunla at 2007-7-10 2:39:29 > top of Java-index,Java Essentials,New To Java...
# 3

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

logictrenda at 2007-7-10 2:39:29 > top of Java-index,Java Essentials,New To Java...
# 4

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

logictrenda at 2007-7-10 2:39:29 > top of Java-index,Java Essentials,New To Java...
# 5
Looks like a Swing question to me (and there is a Swing forum where they should be posted).Why not just use a javax.swing.Timer to do that instead of trying to build it yourself from scratch?
DrClapa at 2007-7-10 2:39:29 > top of Java-index,Java Essentials,New To Java...
# 6
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.
logictrenda at 2007-7-10 2:39:29 > top of Java-index,Java Essentials,New To Java...
# 7

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

warnerjaa at 2007-7-10 2:39:29 > top of Java-index,Java Essentials,New To Java...
# 8
thanks for helping
logictrenda at 2007-7-10 2:39:29 > top of Java-index,Java Essentials,New To Java...