Problems with a clock element
Good Morning,
I just need your advice. I am trying to code a clock element with the java2d. What i thought about is just a string that is repainted each second or minute, depending on the format of the time.
Of course, I don't want to block the main thread with this task, so i tryed to put it into its own one, that can run in the background, calculating the time and write it out.
And this is where my problems start. The element lies in a JPanel and will be called and started by the paintComponent() - function of the JPanel. The call will start the clock thread, and within this thread, i will clear and repaint the timestring.
The thread is started proparly, the functions are called and everything - but nothing appears on the screen.
I think the problem is more the call of the function than the function itself - do I have to go through the JPanel each time I want to repaint the string? Thats what I want to avoid.
This is the run()-function of the clock-element. the Graphics2D will be stored within the class with the first call by the JPanel.
publicvoid run(){
mRunning =true;
while(mRunning){
mText = DateFormat.getTimeInstance(mType, Locale.GERMAN).format(new Date());
if(mTransform){
//Just to draw the string
this.transformTimeElement();
}else{
//Just to draw the string
this.drawTimeElement();
}
try{
Thread.sleep(mSleep);
}catch (InterruptedException e){
//empty by purpose
}
}
}

