QUOTE
We haven't learned GUI yet, but i dont understand methods and loop... :( All the easy stuff...
Which is why Gehn's advice is really good. Figure out methods and loops with simple programs and then start to branch out.
Think of methods as verbs, designed to do a specific task such as
add items to a list,
print out text to the console, etc. That will help you figure out what methods you need. Then to actually make one you have 4 key components in the method signature:
visibility (public/private/protected) return-type (void, int, String, etc.) method-name parameters
CODE
/*
Public method that adds three ints together, returns the result.
*/
public int add(int a, int b, int c) {
return a + b + c;<BR>}
*note there can be more keywords in the method signature such as static, final, synchronized, but I limited my example to the basic ones every method must have with the exception of public, no specified visibility still means its access limited to the same package.
Loops are used to do repeated tasks. There are several types: for, while, do-while.
I'll give an example of a for loop that prints out the numbers from 1 to 10.
CODE
public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
System.out.println(i);
}
}
Now in the for statement this: int i = 1; i <= 10; i++ has the following meaning.
variable i is initialized to one as soon as the program enters the loop. The second part of the statement is a conditional statement that tells Java when to stop looping. If a loop never stops it's called an infinite loop. Before each execution of the for-loop's code block it will check to make sure that conditional is true. After each time it executes the code block the third statement, i++, is executed. All this does is provide a convenient place for the programmer to place simple code to make progress in the loop. Often times loops simply increment/decrement a counter. I don't have to put the increment there, I could put that statement after the call to println, but that's really not good programming style with Java for-loops unless there's a valid reason for doing so.
No doubt that I didn't really help you understand methods/loops very much since I don't know what you don't know, why not ask questions about what you are confused on/don't know/etc and we'll try to point you in the right direction.