M
mery
Neues Mitglied
- 0
Ich bin am Programmieren einer Spiele App, in welcher sich ein Balken über Touch bewegen lasst (am unteren Rand) und ein Ball quer durch das Bild laufen soll. Mit dem Brett soll der Ball dann immer wieder aufgefangen werden. Die einzelnen Funktionen habe ich schon aber ich bekomme es nicht in ein gemeinsammes Fenster rein.
Einen der vielen Ansatz war ein Thread von der anderen klasse zu öffnen, aber das Funktioniert auch noch nicht ganz, denn ich muss da eigentlich eine Information mitgeben, bzgl. wo etwas ausgegeben werden soll oder so, aber das FUnktioniert nicht und auch wenn ich die Variable im Hauptfenster Deklarieren kann es diese im Thread nicht verwenden.
Folgenden Code habe ich schon probiert:
(Hier wierden über die Startklasse zwei butten angezeigt, über einen soll der thread dann gestartet werden. Er wurde zwar schon oben erstellt aber noch auf pause gesetzt. Wenn er dann startet solte er bis 100 Zählen im selben fesnter, aber wie gesagt bis jetzt tut er das noch nicht da die werte für das fenster in der er ausgeben soll nicht mit übergeben werden können. Der andere butten ist für reset und pause) Dieses Beispiel stammt ursprünglich von folgender Seite(obwohl ich es eigentlich relativ eins zu eins übernomen habe funktioniert es nicht): Android
Counter.java
Java Code:
MainActivity.java
Java Code:
Hat jemand eine Lösung oder hilfe zu diesem Code und kann mir da weiter helfen oder sogar zu meinem Grundproblem eine Idee wie ich es machen kann?
Einen der vielen Ansatz war ein Thread von der anderen klasse zu öffnen, aber das Funktioniert auch noch nicht ganz, denn ich muss da eigentlich eine Information mitgeben, bzgl. wo etwas ausgegeben werden soll oder so, aber das FUnktioniert nicht und auch wenn ich die Variable im Hauptfenster Deklarieren kann es diese im Thread nicht verwenden.
Folgenden Code habe ich schon probiert:
(Hier wierden über die Startklasse zwei butten angezeigt, über einen soll der thread dann gestartet werden. Er wurde zwar schon oben erstellt aber noch auf pause gesetzt. Wenn er dann startet solte er bis 100 Zählen im selben fesnter, aber wie gesagt bis jetzt tut er das noch nicht da die werte für das fenster in der er ausgeben soll nicht mit übergeben werden können. Der andere butten ist für reset und pause) Dieses Beispiel stammt ursprünglich von folgender Seite(obwohl ich es eigentlich relativ eins zu eins übernomen habe funktioniert es nicht): Android
Counter.java
Java Code:
Code:
[LIST=1]
[*][COLOR=#000000][B]package[/B][/COLOR] [COLOR=#006699]com.example.threadtest[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.os.Handler[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.widget.TextView[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000000][B]class[/B][/COLOR] Counter [COLOR=#000000][B]implements[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Brunnable%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Runnable[/COLOR][/URL] [COLOR=#009900]{[/COLOR] [COLOR=#666666][I]//private[/I][/COLOR]
[*] [COLOR=#000000][B]private[/B][/COLOR] [COLOR=#000066][B]int[/B][/COLOR] result [COLOR=#339933]=[/COLOR] [COLOR=#cc66cc]0[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]private[/B][/COLOR] [COLOR=#000066][B]boolean[/B][/COLOR] pause [COLOR=#339933]=[/COLOR] [COLOR=#000066][B]false[/B][/COLOR][COLOR=#339933];[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] run[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] pause [COLOR=#339933]=[/COLOR] [COLOR=#000066][B]false[/B][/COLOR][COLOR=#339933];[/COLOR]
[*] result [COLOR=#339933]=[/COLOR] [COLOR=#cc66cc]0[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]while[/B][/COLOR] [COLOR=#009900]([/COLOR][COLOR=#000066][B]true[/B][/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]if[/B][/COLOR] [COLOR=#009900]([/COLOR]pause[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]try[/B][/COLOR] [COLOR=#009900]{[/COLOR]
[*] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bthread%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Thread[/COLOR][/URL].[COLOR=#006633]sleep[/COLOR][COLOR=#009900]([/COLOR][COLOR=#cc66cc]500[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR] [COLOR=#000000][B]catch[/B][/COLOR] [COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Binterruptedexception%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]InterruptedException[/COLOR][/URL] e[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#000000][B]continue[/B][/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] result[COLOR=#339933]++;[/COLOR]
[*] result [COLOR=#339933]=[/COLOR] result [COLOR=#339933]%[/COLOR] [COLOR=#cc66cc]100[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#666666][I]//Diesen erkennt er nicht, bzw. kann er nicht von der Anderen klasse verwenden, aber ich kann ihn hier auch nicht nochmal deklarieren, das geht auch nciht[/I][/COLOR]
[*] handler.[COLOR=#006633]post[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000000][B]new[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Brunnable%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Runnable[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] run[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#666666][I]//Und hier ist es das selbe[/I][/COLOR]
[*] tvStatusNeu.[COLOR=#006633]setText[/COLOR][COLOR=#009900]([/COLOR][COLOR=#0000ff]""[/COLOR] [COLOR=#339933]+[/COLOR] result[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]try[/B][/COLOR] [COLOR=#009900]{[/COLOR]
[*] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bthread%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Thread[/COLOR][/URL].[COLOR=#006633]sleep[/COLOR][COLOR=#009900]([/COLOR][COLOR=#cc66cc]500[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR] [COLOR=#000000][B]catch[/B][/COLOR] [COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Binterruptedexception%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]InterruptedException[/COLOR][/URL] e[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] setPause[COLOR=#009900]([/COLOR][COLOR=#000066][B]boolean[/B][/COLOR] pause[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]this[/B][/COLOR].[COLOR=#006633]pause[/COLOR] [COLOR=#339933]=[/COLOR] pause[COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]boolean[/B][/COLOR] isPause[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]return[/B][/COLOR] pause[COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] reset[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]this[/B][/COLOR].[COLOR=#006633]result[/COLOR] [COLOR=#339933]=[/COLOR] [COLOR=#cc66cc]0[/COLOR][COLOR=#339933];[/COLOR]
[*] handler.[COLOR=#006633]post[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000000][B]new[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Brunnable%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Runnable[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] run[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] tvStatusNeu.[COLOR=#006633]setText[/COLOR][COLOR=#009900]([/COLOR][COLOR=#0000ff]""[/COLOR] [COLOR=#339933]+[/COLOR] result[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*][COLOR=#009900]}[/COLOR]
[/LIST]
Java Code:
Code:
[LIST=1]
[*][COLOR=#000000][B]package[/B][/COLOR] [COLOR=#006699]com.example.threadtest[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.app.Activity[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.os.Bundle[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.os.Handler[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.util.Log[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.view.Menu[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.view.MenuItem[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.view.View[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.view.View.OnClickListener[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.widget.Button[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]import[/B][/COLOR] [COLOR=#006699]android.widget.TextView[/COLOR][COLOR=#339933];[/COLOR]
[*][COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000000][B]class[/B][/COLOR] MainActivity [COLOR=#000000][B]extends[/B][/COLOR] Activity [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]private[/B][/COLOR] [COLOR=#000000][B]static[/B][/COLOR] [COLOR=#000000][B]final[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bstring%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]String[/COLOR][/URL] TAG [COLOR=#339933]=[/COLOR] MainActivity.[COLOR=#000000][B]class[/B][/COLOR].[COLOR=#006633]getSimpleName[/COLOR][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR] [COLOR=#666666][I]//MyThreadExample1Activity[/I][/COLOR]
[*] [COLOR=#000000][B]private[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bbutton%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Button[/COLOR][/URL] bStart[COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]private[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bbutton%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Button[/COLOR][/URL] bReset[COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]public[/B][/COLOR] TextView tvStatus[COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]private[/B][/COLOR] Handler handler[COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]private[/B][/COLOR] Counter worker[COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]private[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bthread%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Thread[/COLOR][/URL] workthread[COLOR=#339933];[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]protected[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] onCreate[COLOR=#009900]([/COLOR]Bundle savedInstanceState[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]super[/B][/COLOR].[COLOR=#006633]onCreate[/COLOR][COLOR=#009900]([/COLOR]savedInstanceState[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] setContentView[COLOR=#009900]([/COLOR]R.[COLOR=#006633]layout[/COLOR].[COLOR=#006633]activty_main[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] handler [COLOR=#339933]=[/COLOR] [COLOR=#000000][B]new[/B][/COLOR] Handler[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] bStart [COLOR=#339933]=[/COLOR] [COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bbutton%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Button[/COLOR][/URL][COLOR=#009900])[/COLOR] findViewById[COLOR=#009900]([/COLOR]R.[COLOR=#006633]id[/COLOR].[COLOR=#006633]main_b_start[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] bReset [COLOR=#339933]=[/COLOR] [COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bbutton%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Button[/COLOR][/URL][COLOR=#009900])[/COLOR] findViewById[COLOR=#009900]([/COLOR]R.[COLOR=#006633]id[/COLOR].[COLOR=#006633]main_b_reset[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] tvStatus [COLOR=#339933]=[/COLOR] [COLOR=#009900]([/COLOR]TextView[COLOR=#009900])[/COLOR] findViewById[COLOR=#009900]([/COLOR]R.[COLOR=#006633]id[/COLOR].[COLOR=#006633]main_tv_status[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] worker [COLOR=#339933]=[/COLOR] [COLOR=#000000][B]new[/B][/COLOR] Counter[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] workthread [COLOR=#339933]=[/COLOR] [COLOR=#000000][B]new[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bthread%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Thread[/COLOR][/URL][COLOR=#009900]([/COLOR]worker[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] worker.[COLOR=#006633]setPause[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000066][B]true[/B][/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] bStart.[COLOR=#006633]setOnClickListener[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000000][B]new[/B][/COLOR] OnClickListener[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] onClick[COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bview%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]View[/COLOR][/URL] v[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bthread%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Thread[/COLOR][/URL].[COLOR=#006633]State[/COLOR] status [COLOR=#339933]=[/COLOR] workthread.[COLOR=#006633]getState[/COLOR][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] Log.[COLOR=#006633]d[/COLOR][COLOR=#009900]([/COLOR]TAG, [COLOR=#0000ff]"status: "[/COLOR] [COLOR=#339933]+[/COLOR] status[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]if[/B][/COLOR] [COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bthread%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Thread[/COLOR][/URL].[COLOR=#006633]State[/COLOR].[COLOR=#000000][B]NEW[/B][/COLOR].[COLOR=#006633]equals[/COLOR][COLOR=#009900]([/COLOR]status[COLOR=#009900])[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#666666][I]// first start[/I][/COLOR]
[*] Log.[COLOR=#006633]d[/COLOR][COLOR=#009900]([/COLOR]TAG, [COLOR=#0000ff]"start"[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] workthread.[COLOR=#006633]start[/COLOR][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] setButtonMsg[COLOR=#009900]([/COLOR][COLOR=#0000ff]"pause"[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] bReset.[COLOR=#006633]setEnabled[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000066][B]true[/B][/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR] [COLOR=#000000][B]else[/B][/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]if[/B][/COLOR] [COLOR=#009900]([/COLOR]worker.[COLOR=#006633]isPause[/COLOR][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] Log.[COLOR=#006633]d[/COLOR][COLOR=#009900]([/COLOR]TAG, [COLOR=#0000ff]"weiter"[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] worker.[COLOR=#006633]setPause[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000066][B]false[/B][/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] bReset.[COLOR=#006633]setEnabled[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000066][B]false[/B][/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] setButtonMsg[COLOR=#009900]([/COLOR]getString[COLOR=#009900]([/COLOR]R.[COLOR=#006633]string[/COLOR].[COLOR=#006633]pause[/COLOR][COLOR=#009900])[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR] [COLOR=#000000][B]else[/B][/COLOR] [COLOR=#009900]{[/COLOR]
[*] Log.[COLOR=#006633]d[/COLOR][COLOR=#009900]([/COLOR]TAG, [COLOR=#0000ff]"pause"[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] worker.[COLOR=#006633]setPause[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000066][B]true[/B][/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] bReset.[COLOR=#006633]setEnabled[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000066][B]true[/B][/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] setButtonMsg[COLOR=#009900]([/COLOR]getString[COLOR=#009900]([/COLOR]R.[COLOR=#006633]string[/COLOR].[COLOR=#006633]weiter[/COLOR][COLOR=#009900])[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] bReset.[COLOR=#006633]setEnabled[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000066][B]false[/B][/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] bReset.[COLOR=#006633]setOnClickListener[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000000][B]new[/B][/COLOR] OnClickListener[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] onClick[COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bview%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]View[/COLOR][/URL] v[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]if[/B][/COLOR][COLOR=#009900]([/COLOR]worker.[COLOR=#006633]isPause[/COLOR][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#009900])[/COLOR][COLOR=#009900]{[/COLOR]
[*] worker.[COLOR=#006633]reset[/COLOR][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] Log.[COLOR=#006633]d[/COLOR][COLOR=#009900]([/COLOR]TAG, getString[COLOR=#009900]([/COLOR]R.[COLOR=#006633]string[/COLOR].[COLOR=#006633]pause[/COLOR][COLOR=#009900])[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] setButtonMsg[COLOR=#009900]([/COLOR]getString[COLOR=#009900]([/COLOR]R.[COLOR=#006633]string[/COLOR].[COLOR=#006633]start[/COLOR][COLOR=#009900])[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]boolean[/B][/COLOR] onCreateOptionsMenu[COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bmenu%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Menu[/COLOR][/URL] menu[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#666666][I]// Inflate the menu; this adds items to the action bar if it is present.[/I][/COLOR]
[*] getMenuInflater[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR].[COLOR=#006633]inflate[/COLOR][COLOR=#009900]([/COLOR]R.[COLOR=#006633]menu[/COLOR].[COLOR=#006633]main[/COLOR], menu[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]return[/B][/COLOR] [COLOR=#000066][B]true[/B][/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]boolean[/B][/COLOR] onOptionsItemSelected[COLOR=#009900]([/COLOR][URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bmenuitem%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]MenuItem[/COLOR][/URL] item[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#666666][I]// Handle action bar item clicks here. The action bar will[/I][/COLOR]
[*] [COLOR=#666666][I]// automatically handle clicks on the Home/Up button, so long[/I][/COLOR]
[*] [COLOR=#666666][I]// as you specify a parent activity in AndroidManifest.xml.[/I][/COLOR]
[*] [COLOR=#000066][B]int[/B][/COLOR] id [COLOR=#339933]=[/COLOR] item.[COLOR=#006633]getItemId[/COLOR][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#000000][B]if[/B][/COLOR] [COLOR=#009900]([/COLOR]id [COLOR=#339933]==[/COLOR] R.[COLOR=#006633]id[/COLOR].[COLOR=#006633]action_settings[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]return[/B][/COLOR] [COLOR=#000066][B]true[/B][/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#000000][B]return[/B][/COLOR] [COLOR=#000000][B]super[/B][/COLOR].[COLOR=#006633]onOptionsItemSelected[/COLOR][COLOR=#009900]([/COLOR]item[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]protected[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] onDestroy[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]super[/B][/COLOR].[COLOR=#006633]onDestroy[/COLOR][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] workthread.[COLOR=#006633]interrupt[/COLOR][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] workthread [COLOR=#339933]=[/COLOR] [COLOR=#000066][B]null[/B][/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#000000][B]private[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] setButtonMsg[COLOR=#009900]([/COLOR][COLOR=#000000][B]final[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Bstring%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]String[/COLOR][/URL] msg[COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] handler.[COLOR=#006633]post[/COLOR][COLOR=#009900]([/COLOR][COLOR=#000000][B]new[/B][/COLOR] [URL="http://www.java-forum.org/redirect-to/?redirect=http%3A%2F%2Fwww.google.com%2F%3Fgws_rd%3Dssl%23q%3Dallinurl%253Adocs.oracle.com%2Bjavase%2Bdocs%2Bapi%2Brunnable%26btnI%3DI%2527m%2520Feeling%2520Lucky"][COLOR=#003399]Runnable[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] @Override
[*] [COLOR=#000000][B]public[/B][/COLOR] [COLOR=#000066][B]void[/B][/COLOR] run[COLOR=#009900]([/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] [COLOR=#000000][B]if[/B][/COLOR] [COLOR=#009900]([/COLOR]msg [COLOR=#339933]==[/COLOR] [COLOR=#000066][B]null[/B][/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR]
[*] bStart.[COLOR=#006633]setText[/COLOR][COLOR=#009900]([/COLOR][COLOR=#0000ff]""[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR] [COLOR=#000000][B]else[/B][/COLOR] [COLOR=#009900]{[/COLOR]
[*] bStart.[COLOR=#006633]setText[/COLOR][COLOR=#009900]([/COLOR]msg[COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*] [COLOR=#009900]}[/COLOR][COLOR=#009900])[/COLOR][COLOR=#339933];[/COLOR]
[*] [COLOR=#009900]}[/COLOR]
[*][COLOR=#009900]}[/COLOR]
[/LIST]