Help on repeteing An applet...

This is based on an earlier post i made (i got it fixed btw guys!).

Anyway, now what im trying to do is loop it so as soon as the integer value goes over 4, it starts the loop over again and resets all the variables. Here is the code..

import java.awt.*;

import java.applet.Applet;

publicclass J19extends Appletimplements Runnable

{

int xPos = 50, yPos = 0, value = 0, counter = 3;

Thread runner;

String[] myarray ={"California","Miami","Germany","Japan","Flordia"};

Color[] theColors ={Color.blue, Color.magenta, Color.pink, Color.orange, Color.green};

publicvoid start()

{

if (runner ==null)

{

runner =new Thread(this);

runner.start();

}//if

}//start

publicvoid run()

{

while(true)

{

if (yPos >= 100)

{

xPos += 3;

if (xPos >= 100 && yPos >= 100){

value = value + 1;//Changes the scrolling text

xPos = 50;

yPos = 0;

}//if

}else{

yPos += 3;

}

repaint();

try{ runner.sleep(100);}

catch (InterruptedException e){}

}//while

}//run

publicvoid paint(Graphics g)

{

g.setColor(theColors[value]);

g.drawString(myarray[value], xPos,yPos);

}//paint

}//J19

[3196 byte] By [Sh4d0wa] at [2007-11-27 6:43:36]
# 1
Add this line of code in ur run() function ... the first statementif(value > myarray.length)value = 0;
nix365a at 2007-7-12 18:14:33 > top of Java-index,Java Essentials,Java Programming...
# 2

It would appear their were no changes in my code. Mind explaining what that supposadly should do? I tried a few variations, but it just stops running.

Incase i did somthing wrong, here is the edited part...

public void run()

{

if(value > myarray.length)

value = 0;

while(true)

{

Sh4d0wa at 2007-7-12 18:14:33 > top of Java-index,Java Essentials,Java Programming...
# 3
OOps sorry thereit should beif(value == myarray.length)value = 0;So whenever value has a value 5 it will be reassigned to 0
nix365a at 2007-7-12 18:14:33 > top of Java-index,Java Essentials,Java Programming...
# 4
put it in the paint() function
nix365a at 2007-7-12 18:14:33 > top of Java-index,Java Essentials,Java Programming...
# 5

while(true)

{

if (yPos >= 100)

{

xPos += 3;

if (xPos >= 100 && yPos >= 100) {

value = value + 1; //Changes the scrolling text

if(value >= myarray.length)

value = 0;

The point of resetting value is to prevent theColors and myArray from being accessed outside of their bounds. You have to check if value is too high after you increment it.

hunter9000a at 2007-7-12 18:14:33 > top of Java-index,Java Essentials,Java Programming...