Hmm…
Looks like implementing threads is going to be about what I
expected. The code is simple
enough. It’s getting that thread to run
multiple times on a schedule that’s going to be the complicated part. I have no idea how to get it to do that. The thread.sleep() should cause it to work,
but it’s not doing what it’s supposed to do.
I suppose I’m used to dealing with threading causing me havoc.
Grr… Slight
modifications to the system and it still doesn’t work. But eh…
The real problem is threading is critical to half of the
stuff I have running through my head. So
I have to figure out threading, or the rest of my ideas need to go on
hold. And I really don’t want to put
them on hold.
But… grr.
Did I mention I’ve never been good at threads? In general, they seem to be easy. But I’ve never been able to implement them
properly. Though quickly looking through
the Java documentation, there is also a timer implementation that would probably
implement the countdown portion of the clock just fine. It still annoys me…
Yeah, I still hate threads. I wouldn't bother trying the code, as it doesn't work...
private class CountDown implements Runnable
{
CountDown()
{
}
public void start()
{
t = new Thread(this, "counter");
t.start();
}
public void run()
{
try
{
int ones;
int tens;
String txt = seconds.getText();
char characters[] = txt.toCharArray();
ones = characters[1] - '0';
tens = characters[0] - '0';
ones = ones - 1;
if(ones < 0 && tens > 0)
{
tens = tens -1;
ones = 9;
}
else if(ones < 0 && tens == 0)
{
tens = 0;
ones = 0;
}
seconds.setText( Integer.toString(tens) + Integer.toString(ones));
Thread.sleep(20);
}
catch(InterruptedException e)
{
}
}
}
No comments:
Post a Comment