title: Text Banner applet reverses that displayes text
body: <p>i'm working on applet that displays a moving banner horizontally and when this text banner 
  reaches the right boundary of the applet window it should be appear reversed from the start of the left boundary, i write the following class to do the work, the problem is that when the text banner reaches the right banner it crashes, the applet goes to infinite loop:</p>
  
  <pre><code>    import java.applet.*;
      import java.awt.*;
      import java.net.*;
      import java.io.*;
      import javax.swing.*;
  
      /*
      &lt;applet code="banner" width=300 height=50&gt;
      &lt;/applet&gt;
      */
      public class TextBanner extends Applet implements Runnable 
      {
          String msg = "Islam Hamdy", temp="";
          Thread t = null;
          int state;
          boolean stopFlag;
          int x;
          String[] revMsg;
          int msgWidth;
          boolean isReached;
  
           public void init() 
          {
  
              setBackground(Color.BLACK);
              setForeground(Color.YELLOW);
          }
  
          // Start thread
  
          public void start() 
          {
  
              t = new Thread(this);
              stopFlag = false;
              t.start();
          }
  
          // Entry point for the thread that runs the banner.
  
          public void run() 
          {
  
              // Display banner
              while(true) 
              {
                  try 
                  {
                      repaint();
                      Thread.sleep(550);
                      if(stopFlag)
                          break;
                  } catch(InterruptedException e) {}
              }
          }
  
          // Pause the banner.
  
          public void stop() 
          {
              stopFlag = true;
              t = null;
          }
  
          // Display the banner.
  
          public void paint(Graphics g) 
          {
          String temp2="";
          System.out.println("Temp--&gt;"+temp);
          int result=x+msgWidth; 
          FontMetrics fm = g.getFontMetrics();
          msgWidth=fm.stringWidth(msg);
          g.setFont(new Font("ALGERIAN", Font.PLAIN, 30));        
          g.drawString(msg, x, 40);
          x+=10;
          if(x&gt;bounds().width){
          x=0;
      }
          if(result+130&gt;bounds().width){
           x=0;
          while((x&lt;=bounds().width)){
          for(int i=msg.length()-1;i&gt;0;i--){
          temp2=Character.toString(msg.charAt(i));
          temp=temp2+temp;
                      // it crashes here
          System.out.println("Before draw");
              g.drawString(temp, x, 40);
          System.out.println("After draw");
          repaint();
                 }
              x++;
              }       // end while
           }          //end if
  
        }
  
       }
  </code></pre>