I was wondering how to create a moving banner using Java Applets without threads. I got it this far but the program doesn't repaint.
import java.applet.*;
import java.awt.*;
/*<applet code="bt" height=300 width=300></applet>*/
public class bt extends Applet{
String msg="This banner is soo cool!!!";
String hm;
char c;
public void init(){
setBackground(Color.cyan);
setForeground(Color.red);
}
public String bann(String mg){
c=mg.charAt(0);
hm=mg.substring(1,mg.length());
hm+=c;
repaint();
return hm;
}
public void paint(Graphics g){
try{
for( ; ; ){
g.drawString(msg,100,100);
Thread.sleep(2000);
msg=bann(msg);
}
} catch(InterruptedException e) {}
}
}
Moreover, i can't close the window by just clicking exit. I have to force Quit it. It would be nice if someone could explain why.