Hallo,
habe ein kleines Problem, vielleicht könnt ihr mir helfen.
Meine Klasse soll in Abhängigkeit von der Button-Stellung alle 2,5 Sek. etwas ausgeben.
Der Vergleich den ich dabei anstelle funktioniert aber nicht, habe leider keine Ahnung wieso.
Der Teil um den es geht, ist rot markiert.
habe ein kleines Problem, vielleicht könnt ihr mir helfen.
Meine Klasse soll in Abhängigkeit von der Button-Stellung alle 2,5 Sek. etwas ausgeben.
Der Vergleich den ich dabei anstelle funktioniert aber nicht, habe leider keine Ahnung wieso.
Der Teil um den es geht, ist rot markiert.
Java:
//Aufgabe 2e
package WS07_08.Aufgabe2_Enum;
public class Playercore extends Thread {
public enum Zustand {PLAYING, STOPPED, OFF};
private Zustand zustand;
static boolean isCreated = false;
//static int count = 0;
public void run() {
while(!isInterrupted()) {
try {
[COLOR="Red"]if (Zustand.PLAYING == zustand) {
System.out.println("Pling");
}
if (zustand==Zustand.STOPPED) {
System.out.println(".");
}[/COLOR]
else {
}
Thread.sleep(2500);
System.out.println("Ich laufe noch!");
}
catch (Exception e) {
}
}
}
Playercore() throws Exception {
zustand = Zustand.OFF;
//count++;
//isCreatedCheck();
isCreated = true;
}
public void play() {
zustand = Zustand.PLAYING;
System.out.println(zustand);
}
public void stopPlayer() {
zustand = Zustand.STOPPED;
System.out.println(zustand);
}
public void off() {
zustand = Zustand.OFF;
System.out.println(zustand);
}
public Zustand getPlayerState() {
//System.out.println(count);
return zustand;
}
private void isCreatedCheck() throws Exception {
if (isCreated) {
throw new Exception();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Playercore thread1 = new Playercore();
Playercore p1 = new Playercore();
System.out.println(p1.getPlayerState());
p1.play();
thread1.start();
}
catch (Exception e) {
System.out.println("Objekt bereits vorhanden");
}
}
}