Forums Register Login

Need Help

+Pie Number of slices to send: Send
Want to Construct a javax.swing.Timer object such that the message �Happy Birthday to you� is displayed on a Text Field once per second
+Pie Number of slices to send: Send
The key point here is something you have missed: what happens in between each second? Because it is no good displaying the message every second if the previously displayed one is still there!

That said, you should create your Timer instance with the appropriate delay (1000 milliseconds). In your class that creates the text field, implement ActionListener. In the actionPerformed method, change the text of the text field as required.

If you want to flash the text (i.e. on for one second, off for one second), generate a timer that pauses for 1000 milliseconds. Then implement some kind of boolean flag to say whether this second you should shown the message or erase it.

The Timer API docs will be able to help you too.
+Pie Number of slices to send: Send
Moni,
You need to write one thread for this.Inside Threads run() method you put the code which display 'Happy birthday'.

Like
if(txtfld.getText().equals(""))
{
txtfld.setText(" H");
}
else if(txtfld.getText().trim().equals("H"))
{
txtfld.setText(" Ha");
}

Dont forget to put
Thread.sleep(milliseconds);
at the end.

Hope this helps you.
+Pie Number of slices to send: Send
 

Originally posted by Amol Fuke:
Moni,
You need to write one thread for this.Inside Threads run() method you put the code which display 'Happy birthday'.

Like
if(txtfld.getText().equals(""))
{
txtfld.setText(" H");
}
else if(txtfld.getText().trim().equals("H"))
{
txtfld.setText(" Ha");
}

Dont forget to put
Thread.sleep(milliseconds);
at the end.

Hope this helps you.



If this is what the OP wants then a better way to display the string is


[ September 06, 2005: Message edited by: Joanne Neal ]
[ September 06, 2005: Message edited by: Joanne Neal ]
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 972 times.
Similar Threads
javax.swing.Timer
Serious Problem with JDialog NOT A MODAL for ...
using the Timer class in javax.swing
Happy Birthday Sriraj Rajaram
painting hundreds of Rectangles in JPanel
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:07:32.