Miko Jing wrote:Normally or every time doing java code, i will always doing it in one java main class.
Bad move...as you appear to be discovering.
And now i was wondering how to create a mutiple class from one main class? By calling method? abit confuse...
You may find the
MainIsAPain page worth reading, because only ONE of your classes needs a
main() method - and it should be
tiny.
To start out with, you're probably best off to keep all related classes in a single package, and then you create and use them just like you would any other Java class, eg:
String msg = new String("Well, Hello World");
System.out.println( msg.subtring(6) );
(The underlined names are Java classes, and the
new is for illustration only)
Later on, you'll learn how to arrange them more "smartly" and use the
import statement.
But, as most of the others have said, some of your methods are much too big. My rule of thumb is a screenful of code,
MAX (≈30-40 lines), but you might want to start out even smaller.
So, a couple of basic rules that may help you:
1. Before you write ONE LINE of Java code, make sure you know
what you want to do. Write it out
on paper, in detail, and
in English (or your native language) first.
For more info on this, you may find the
WhatNotHow (←click→) and
StopCoding pages useful.
2. If you have a method that is more than ≈20 lines long,
break it up. You won't
always be able to do this, but alarm bells should start to go off when you find yourself writing enormous methods.
HIH
Winston