Re: applet problem (solved)
Did you see the one I made with a thread? It's in the same thread(forum thread!) as Andy's, but mine scrolls horizontal.
Re: applet problem (solved)
Re: applet problem (solved)
here is your code
Code:
public void run()
{
/* we start a while loop, that will loop will it is true, and since
* nothing ever makes it false it never stops. So no matter how long the
* program is run, it will always be going.
*/
while (true)
{
/* Since we are working with threads, we must put our operations in a try
* catch clause so that we can trap errors that will possibly arise.
*/
try
{
/* get the old text, which is just the text on the JLabel at this
* moment. We will need this later.
*/
String oldText = adLabel.getText();
/* create a new String, that will perform some operations on the old text
* and then set the text of the JLabel to the new text. The first part of this
* (substring(0)), takes one parameter, this parameter is the starting index of the
* string, and then grabs everything else. Again, index's start at index 0, so this
* is cutting the string off by one. So, if the text is "text", then the first part
* cuts it down to "ext". Then you have the concatenating operater(+) that adds text
* to the preceding string. The third part, oldText.substring(0,1), has two parameters,
* the beginning index, and the ending index. We specify 0, and 1. This basicly means it
* grabs the first character of the old text. So, if we had "text", as the label, then it
* would get the "t" out of text since it is the first letter. Then that is added to the\
* first operation(where we got "ext"....This ends up putting the text as "extt", but of course
* if you had spaces after the message, it would be much clearer("ext t", then "xt te", then
* "t tex", and last " text", and it would loop from there.
*/
StringBuffer newText = StringBuffer.append(oldText.substring(1) + oldText.substring(0, 1));
//set the text of the label to the new text
adLabel.setText(newText);
/* The thread class has a method called sleep(). This method will pause the thread for a given
* amount of time in milliseconds. We specify 250, but this can be changed. You put the time
* in milliseconds as the parameter for the method.
*/
Thread.sleep(250);
}
/* If you use a thread, you must catch the interrupted exception. This exception
* will occur if the thread is interrputed in anyway, hence the name interrupted
* exception. If this exception occurs, we don't want to continue.
*/
catch (InterruptedException e)
{
/* Since we don't want to continue if this exception occurs, we make a call to
* the stop method. This wll stop the thread all together.
*/
stop();
}
}
I can't make it run in my applet because of this:
StringBuffer newText = StringBuffer.append(oldText.substring(1) + oldText.substring(0, 1));
for some reason it makes an error...
Re: applet problem (solved)
What was the error?
I did this on a label, so that could be your problem. You must have the text on a label, or else you'll have to change a few lines.
Re: applet problem (solved)
I added a label called adLabel but the problem comes from the append on the substring... it can't be done this way and maybe when I try to modify it I change it's effect in the applet and nothing works.