Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setBackground() infinite loop

 
Arun kumar Maalik
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void paint(Graphics g){

setBackground(new Color(c1,c2,c3));

if(c1>=210)
c1=0;
else
if(c2>=220)
c2=0;
c2+=10;
c1+=10;
}

Hey frnd in the above code ,when i excute this program it is going in infinite loop, if i m removing code c1+=10 and c2+=10 then it work well why although c1, c2 is defined as class memeber.
 
Joe Ess
Bartender
Posts: 9370
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My wild guess would be that changing the background color causes the applet to repaint itself, invoking the paint() method, changing the background color and causing another repaint. . .
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!