I have had to repaint a couple of times because of a moving shape I have added to my program whenever the mouse is clicked. I also have a moving shape that follows the mouse over a grid as well which doesn't help a lot, could you please tell me how to reduce this flickering?
The code I have used for the moving counter is:
/* Show the counter appearing above the columns the mouse is over between the restricted co-ordinates and set the counter to the colour depending on the player turn */
if(xPosCounter >= leftXPos && xPosCounter <= rightXPos)
{
g.setColor(counterColour);
g.fillOval(xPosCounter-(counterWidth/2), yPos - counterHeight*grid[0].length, counterWidth, counterHeight);
}
And for the animation I have used a timer with a delay of 100 frames per second and this is repainted in action performed but what really started the bad flickering was when I had to add a repaint here:
int lowestYPosition = lowestRow;
lowestFallingPosition = (lowestYPosition * (counterHeight + gapBetweenCounterSlots)) + topYPos;
//Droppping counter
if(unfrozen == true && yPositionMovingCounter < lowestFallingPosition) { //Ypos starts at the beginning of the grid and ends at the bottom
startAnimation();
yPositionMovingCounter = yFwdLine (topYPos,15);
g.setColor(Color.red);
g.fillOval (centeredCounterInColumn, yPositionMovingCounter, counterWidth, counterHeight);
repaint();
If I didn't my grid disappeared. I could really do without this flickering because it makes my program look rubbish. Anyone know any methods for this?