Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet problem... need help!

 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want to do is add a second city to my applet. The code is here:


import java.awt.*;import java.applet.Applet;

public class Animation extends Applet implements Runnable
{
String textToScroll = "Toronto";
int yPos = 0;
Thread runner;

public void start()
{
if (runner == null)
{
runner = new Thread(this);
runner.start();
}
}

public void run()
{
while(true)
{
if (yPos > getSize().height)
{
yPos = 0;
}
else
{
yPos += 2;
repaint();
try
{
runner.sleep(160);
}
catch (InterruptedException e) { }
}
}
}

public void paint (Graphics g)
{

setBackground (Color.blue);

g.setColor (Color.red);
g.drawString(textToScroll, 160, yPos);

}

}





What happens now is Toronto scrolls down the screen in red and then repeats back at the top. I need something like Paris to scroll down from the top as soon as Toronto hits the bottom and then when Paris hits the bottom I want the entire thing to repeat and start back at toronto. To display the code make the width 400 and height say.... 600. The file name is called Animation. Please... its driving me nuts!!
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So whenever you now set yPos to zero, you also need to switch between the two strings. That doesn't sound too hard. You could keep all strings in an array, and adjust the index into the array whenever you reset yPos to 0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic