We can override the
paintComponent(Graphics g) method of
It is called automatically to refresh the screen.
What can I do that is called regularly, for example every 100 ms.
Is this possible?
Maybe your purpose is refreshing the component every certain ms?
If so, there's a few options available.
The use of
Timer is a first option. Example here.
The option most people use is
Thread animation. Here is an example.
Also there's a timing framework available to download. I can't find an available link, but just search for it on the internet.
Hope this helps.
You can request that the component repaint itself with a call to repaint(). You most certainly do not want to call repaint every 1 ms though; no monitor in the world could display at 1000 Hz, and no human eye would distinguish that either. Furthermore the repaint calls would be coalesced into a few separate ones and you would not achieve that number of repaints.
What are you trying to achieve? I assume it's some sort of animation; if so you should start googling for "java 2d swing animation" or some variant of that. Try this 2d java tutorial for starters.