944,010 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1348
  • Java RSS
Mar 25th, 2005
0

How would you do this?

Expand Post »
How would you put a scrolling message on your application with a seperate thread, sort of like an advertisment?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 27th, 2005
0

Re: How would you do this?

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 27th, 2005
0

Re: How would you do this?

Thank you, it was easier than I thought. I made one with the timer thread, and one with the original thread in sleep mode.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 27th, 2005
0

Re: How would you do this?

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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 28th, 2005
0

Re: How would you do this?

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 28th, 2005
0

Re: How would you do this?

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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 28th, 2005
0

Re: How would you do this?

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.

Java Syntax (Toggle Plain Text)
  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. }
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 28th, 2005
0

Re: How would you do this?

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: calling the internet browser from a java applet
Next Thread in Java Forum Timeline: Converting Int to bytes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC