Hi,
I’ve wrote an application that extends Canvas that needs to draw images on screen. I have 2 paint methods, one draws images and the other clears the screen. The 2 paint methods are as follows:
public void clearScreen()
{
Graphics2D g = (Graphics2D)buffer.getDrawGraphics();
Rectangle2D clear = new Rectangle2D.Double(0,0,(int)3*this.getWidth()/4, this.getHeight());
g.setColor(Color.lightGray);
g.fill(clear);
Rectangle2D divisionArea = new Rectangle2D.Double((int)3*this.getWidth()/4, 0,this.getWidth(),this.getHeight());
g.setColor(Color.gray);
g.fill(divisionArea);
}
and
public void paintQuestions()
{
Graphics2D g = (Graphics2D)buffer.getDrawGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
for(int i = 0; i<selectedQuestionList.size(); i++)
{
selectedQuestionList.get(i).draw(g);
selectedAnswerList.get(i).draw(g);
}
}
The paint questions and clear the screen methods are continually called within the following thread:
class UpdateThread extends Thread
{
public void run()
{
clearScreen();
paintQuestions();
while(true)
{
try
{
sleep(130);
}
catch(InterruptedException e){}
}
}
}
Is there a way to implement the paint methods and update the screen WITHOUT using a thread since the thread is causing a few problems to the application.
Help would be much appreciated.
Thanks,
Nick