How would you do this?

Reply

Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

How would you do this?

 
0
  #1
Mar 25th, 2005
How would you put a scrolling message on your application with a seperate thread, sort of like an advertisment?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,144
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How would you do this?

 
0
  #2
Mar 27th, 2005
Just like that
I guess it's a Swing app?
Make a JPanel, put a Timer on it which on every tick rotates the text in a StringBuffer one character (or however much) and sets it to a JLabel on that JPanel.

Add the assembly to your application and turn on the timer.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: How would you do this?

 
0
  #3
Mar 27th, 2005
Thank you, it was easier than I thought. I made one with the timer thread, and one with the original thread in sleep mode.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: How would you do this?

 
0
  #4
Mar 27th, 2005
I used a JLabel, and deleted the first character and added it on the end of the text. Then the thread did the rest. It was kind of cool, bu not as hard as I expected.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,144
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How would you do this?

 
0
  #5
Mar 28th, 2005
If you use a single String you may want to check your performance and memory usage.
Could get substantial as Strings are immutable and thus a new String is being created for each iteration.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: How would you do this?

 
0
  #6
Mar 28th, 2005
YOUR RIGHT! I didn't even think of that, and I was wondering why it was kind of jumpy, or seemed laggy. I'll change it to a BufferedString and get back to you on the physically visable performance. Anyways, thank you for pointing that out.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: How would you do this?

 
0
  #7
Mar 28th, 2005
Is there a way I can some how work the StringBuffer in this method, because I'm using substrings, and I guess that would contribute to a performance loss.

  1. public void run()
  2. {
  3. while (true)
  4. {
  5. try
  6. {
  7. String oldText = adLabel.getText();
  8. String newText = oldText.substring(1) + oldText.substring(0, 1);
  9.  
  10. adLabel.setText(newText);
  11. Thread.sleep(250);
  12.  
  13. }
  14. catch (InterruptedException e)
  15. {
  16. stop();
  17. }
  18. }
  19. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,144
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How would you do this?

 
0
  #8
Mar 28th, 2005
One way would be to build an array of characters when setting the text and building up a stringbuffer based on the content of that array (keeping the current index of the first character in memory) during each iteration.
You can then simply call toString() on the StringBuffer in order to set the text.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC