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

Username:   Password: 
 RegisterRegister   
 For loops in applets
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Master




PostPosted: Sat May 22, 2004 11:01 pm   Post subject: For loops in applets

i have a program - type of asteroids game - in which you can shoot the asteroids. If everytime i press "shoot" i get the number of shots to appear on the screen, but everytime i have to use:

g2.fill(shot[a])

instead i want to use a for loop so i can have it draw the amount that was pressed:

for (int i =0; i >= shotPressedl; i++)
{
g2.fill(shot[i]
}

what i have is:
g2.fill(shot[a])
g2.fill(shot[b])
g2.fill(shot[c])... and for ever

what happens is that my program wont recognize my for loop or it just wont execute for some reason. Is there a restriction that i cannot use loops in a paint method of an applet?
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Sat May 22, 2004 11:47 pm   Post subject: (No subject)

try making i >= shotPressedl in to i <= shotPressedl

since i starts at 0 and gose up not the other way around.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Master




PostPosted: Sun May 23, 2004 10:48 pm   Post subject: (No subject)

Quote:
try making i >= shotPressedl in to i <= shotPressedl


i understand, but this statement is always true and it will never run
i is always less than the number of shots pressed

this is my code which isnt working
code:

for (int i = 0; i >= shotPressed; i++)
{
        g2.fill(fire1[i - 1]);
}

for some reason this for loop doesnt seem to be even executing. Could someone please help me
thanks
Tony




PostPosted: Sun May 23, 2004 11:15 pm   Post subject: (No subject)

Master wrote:

i understand, but this statement is always true and it will never run

*smack*
now that I got your attention... you do realize that the loop is executed while the statement is true, right?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Master




PostPosted: Mon May 24, 2004 10:23 pm   Post subject: (No subject)

for (int i = 0; i >= shotPressed; i++)
{
g2.fill(fire1[i - 1]);
}

even if this loop executes, it will not follow my instructions... it will not fill the object. Do you know what is wrong. IT FEELS LIKE THE LOOP DOESNT EXECUTE EVEN THOUGH IT MAYBE EXECUTING. I want the loop to execute and run properly atleast once, because when i tell it to run, it just wont work.
Tony




PostPosted: Mon May 24, 2004 11:33 pm   Post subject: (No subject)

do you know how to read? Thinking no?
code:

for (int i = 0; i <= shotPressed; i++)
{
g2.fill(fire1[i]);
}
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: