Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 For loops inside an Applet's paint/repaint method?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic
Author Message
RedRogueXIII




PostPosted: Wed May 16, 2007 4:25 pm   Post subject: For loops inside an Applet's paint/repaint method?

Is it possible to call a for loop inside an applet's paint method? I have coded it to draw multiple objects using a for loop, however none of the code inside the for loop shows up upon execution. If not, is there any way to draw elements to the screen without having to write the code for every added element?
 
Sponsor
Sponsor
Sponsor
sponsor
iluvchairs112




PostPosted: Wed May 16, 2007 5:01 pm   Post subject: Re: For loops inside an Applet's paint/repaint method?

i'm not complete sure what you're asking ... however this might work

for(int a=1; a>=10, a=a+1)
{
fillOval(x, x, 1, 1);
x=x+1;
}

something like that, perhaps?
 
RedRogueXIII




PostPosted: Wed May 16, 2007 5:51 pm   Post subject: Re: For loops inside an Applet's paint/repaint method?

code:
        public void paint(Graphics g){
                g.setColor(Color.black);
                g.fillRect( 0, 0, WIDTH, HEIGHT);//Background            
                g.setColor(Color.white) ;
                for(int i = 0; i > ballArray.length; i++){//Draw all balls.
                        g.fillOval( ballArray[i].x, ballArray[i].y, ballArray[i].size, ballArray[i].size);
                }
                for(int i = 0; i > player.length; i++){// Draw all paddles.               
                        g.fillRect( player[i].x - 5, player[i].y - player[i].size, 5, player[i].size * 2);
                }
                g.setColor(Color.red); 
                g.drawString(message,WIDTH/2,HEIGHT/2); 
        }

That is my code, however the for loops themselves seem to be ignored, as nothing inside is recognized or executed. Is this a limitation and if so are there any alternative methods to drawing a dynamic amount of elements?

*EDIT : AHAHAHAHAHA I'm an idiot, if you check my code, notice the greater and equal statements in my code. Thats was my problem the whole time. Embarassed
 
Luny




PostPosted: Wed May 16, 2007 7:47 pm   Post subject: RE:For loops inside an Applet\'s paint/repaint method?

Yeah, just flip the > signs in your for loop to < and it should work!
 
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: