Developing Games in Java£¨²¿·Ö£©
ÔÎÄÀ´×ÔÓÚ¡¶Developing Games in Java¡·£¬×÷ÕߣºDavid Brackeen, Bret Barker, Laurence Vanhelsuwé
JavaÔÚÉè¼ÆÊ±³ä·Ö¿¼ÂÇÁËÏß³Ì,Òò´ËÔÚJavaÖÐÏ̵߳IJÙ×÷±ÈÆäËûÓïÑÔÒª¼òµ¥¡£Ö»ÐèÉú³ÉÒ»¸öThreadÀàµÄʵÀý±ã¿É´´½¨Ò»¸öỊ̈߳¬È»ºóµ÷ÓÃstart()·½·¨Ïß³Ì¾ÍÆô¶¯ÁË¡£
Thread myThread=new Thread();
myThread.start();
µ±È»£¬Õâ¶Î´úÂëûÓÐÈκÎʵ¼ÊÒâÒ壬ÒòΪ¸ÃÏß³ÌÖÐûÓаüº¬ÈκÎÈÎÎñ¡£JavaÐéÄâ»ú´´½¨Ò»¸öеÄϵͳÏ̺߳󣬱ãÆô¶¯¸ÃỊ̈߳¬È»ºóThread¶ÔÏóµÄrun()·½·¨±»µ÷Óá£Ä¬ÈÏÇé¿öÏ£¬run()·½·¨²»×öÈκι¤×÷£¬Òò´Ë£¬Ï̱߳ãËæ¼´Í£Ö¹¡£
Èç¹ûÏëÈÃÏß³ÌÍê³ÉijÏîÈÎÎñ£¬ÔÚrun()·½·¨ÖÐÌí¼ÓÏàÓ¦´úÂë¼´¿É¡£ÓÐÈýÖÖ»ù±¾µÄ·½·¨¿ÉÒÔʵÏÖÕâÒ»²Ù×÷:
1£¬¼Ì³ÐÀ©Õ¹ThreadÀà
2£¬ÊµÏÖRunnable½Ó¿Ú
3£¬Ê¹ÓÃÄäÃûÄÚ²¿Àà
¼Ì³ÐÀ©Õ¹ThreadÀà
¸øÏ̷߳ÖÅäÈÎÎñµÄÒ»¸ö¿ì½ÝµÄ·½·¨ÊǼ̳ÐÀ©Õ¹ThreadÀ࣬²¢ÖØÐ´run()·½·¨£º
public class MyThread extends Thread {
public void run() {
System.out.println("Do something cool here.");
}
}
È»ºó´´½¨ºÍÆô¶¯Ị̈߳º
Thread myThread = new MyThread();
myThread.start();
ÏÖÔÚÓÐÁ½¸öÏß³ÌÕýÔÚÔËÐУºmainÖ÷Ï̺߳ÍÄã¸Õ²ÅÆô¶¯µÄÄǸöÏ̡߳£
ʵÏÖRunnable½Ó¿Ú
¼Ì³ÐÀ©Õ¹ThreadÏ̹߳ÌÈ»¼òµ¥£¬µ«´ó¶àÊýÇé¿öÏÂÄã¿ÉÄÜÖ»ÊÇÏëÆô¶¯Ò»¸öÏ̶߳ø²¢·ÇÖØÐ±àдÀà¡£ÀýÈ磺ÓÐÒ»¸öÀàÒѾ¼Ì³ÐÀ©Õ¹ÁËÆäËûÀ࣬µ«ÄãÈÔÏ£Íû½«Ëü×÷Ϊһ¸öÏ̡߳£ÔÚÕâÖÖÇé¿öÏÂÖ»ÓÐʵÏÖRunnable½Ó¿Ú£º
public class MyClass extends SomeOtherClass implements Runnable {
public MyClass() {
Thread thread = new Thread(this);
thread.start();
}
public void run() {
&n
Ïà¹ØÎĵµ£º
JavaÃæÊÔÖУ¬×î³£±»ÈËÎʵ½µÄ¼¸¸öÎÊÌ⣺
1. java.util.*°üµÄUML½á¹¹Í¼¡£
2. VectorºÍArrayList¡¢LinkedListÇø±ð Hashtable ºÍ HashMapÖ®¼äµÄÇø±ð
3. String¡¢StringBuffer£¬StringBuilderÖ®¼äÇø±ð¡£
--»Ø´ð--
1.
Collection
|
|_List
| |_LinkedList
| | ......
this
¶ÔÏó±¾Éí¡£public class ThisTest {
ThisTest tTest;
public ThisTest(){
tTest = this;
}
public void test(){
System.out.println(this);
}
public static void main(String arg[]){
new ThisTest().test();
}
}
³ÉÔ±·½·¨ÒýÓá£
³ÉÔ±±äÁ¿ÒýÓá£public class ThisTest {
String name ......
ÔÚjava±à³Ì˼ÏëÖжÔsynchronizedµÄÒ»µã½âÊÍ:
1¡¢synchronized¹Ø¼ü×ÖµÄ×÷ÓÃÓòÓжþÖÖ£º
1£©ÊÇij¸ö¶ÔÏóʵÀýÄÚ£¬synchronized aMethod(){}¿ÉÒÔ·ÀÖ¹¶à¸öÏß³Ìͬʱ·ÃÎÊÕâ¸ö¶ÔÏóµÄsynchronized·½·¨£¨Èç¹ûÒ»¸ö¶ÔÏóÓжà¸ösynchronized·½·¨£¬Ö»ÒªÒ»¸öÏ̷߳ÃÎÊÁËÆäÖеÄÒ»¸ösynchronized·½·¨£¬ÆäËüÏ̲߳»ÄÜͬʱ·ÃÎÊÕâ¸ö¶ÔÏóÖÐÈκÎÒ»¸ö ......
1.
Ôö¼ÓJavaÓ¦ÓÃ
ÔÚandroid_2.1/packages/appsÔö¼Ó¸ÃÏîÄ¿£»
ÔÚbuild/target/product/generic.mkµÄPRODUCT_PACKAGESºóÃæÔö¼Ó¶ÔÓ¦°üµÄÃû×Ö¡£
1.1
´ÓÃüÁîÐ ......
1.½«Int,Float,Double,Longת»»ÎªString
String s = ""+i;
String s = String.valueOf(i);
String s = Integer.toString(i);
µÚÒ»ÖÖ·½·¨£ºs = ""+i; //»á²úÉúÁ½¸öString¶ÔÏó
µÚ¶þÖÖ·½·¨£ºs=String.valueOf(i); //Ö±½ÓʹÓÃStringÀàµÄ¾²Ì¬·½·¨£¬Ö»²úÉúÒ»¸ö¶ÔÏó
µÚÈýÖÖ·½·¨£ºÐ§ÂÊ×î¸ß£¿
2.½«Stringת»»ÎªIn ......