Before asking my question, I apologize for any inconsistencies. I am new to this. I am making a game that currently looks like this (the picture is not important): 
The red dots should move to the right, and they do this with a timer. It works great. The graphics are not updated, so I have to drag the side of the window back and forth to see that my points are moving. What can I do to fix this?
My paintcomponent method in my main class:
public void paintComponent(Graphics g){ super.paintComponent(g); for (int x = 0; x < SomeInts.amount; x++){ for (int y = 0; y < SomeInts.amount; y++){ tile[x][y].colorBody(g, x, y); Tower temp; for (int i = 0; i < towers.size(); i++){ temp = towers.get(i); temp.colorBody(g, tile[x][y].getSize()); temp.guard.colorBody(g, tile[x][y].getSize()); } } } }
My class of red dots. Also called the Guard class:
public class Guard { int x, y, size = 10, towerx, towery; Timer timer; public Guard(int towerx1, int towery1){ towerx = towerx1; towery = towery1; x = towerx + 1; y = towery; new Timer().schedule(new MyTask(), 1000, 1000); } public void colorBody(Graphics g, int tilesize){ g.setColor(new Color(255, 0, 0)); g.fillOval(x * tilesize + tilesize / 4, y * tilesize + tilesize / 4, size, size); } public class MyTask extends TimerTask { public void run() { x++; } }
}
Thank you for your time.
source share