How would you put a scrolling message on your application with a seperate thread, sort of like an advertisment?

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.

Thank you, it was easier than I thought. I made one with the timer thread, and one with the original thread in sleep mode.

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.

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.

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.

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.

public void run()
    {
    	while (true)
    	{
     	   try
      	  {        
      	      	String oldText = adLabel.getText();
				String newText = oldText.substring(1) + oldText.substring(0, 1);
				
				adLabel.setText(newText);
          	  Thread.sleep(250);

          }
             	catch (InterruptedException e)
       		{
           	      stop();
                }
    }
  }

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.