I'm making a small GUI program that fetches coordinates from a server and then paints them on a grid. The painting part works, but there are artifacts until the coordinates are finished fetching from the server. I'm guessing it has to do with the fact that I'm setting the coordinates on the grid before it is finished populating. I'm drawing the coordinates on the grid using paintComponent(Graphics g) method. I assume the way to fix this is to perhaps implement some multithreading so that the the program needs to wait for the coordinates to be populated before drawing them to the screen but I'm not sure how to go about that.
Here is my setup so far:
GUI: JFrame
- main method
- sets up GUI with components
- helper methods to fetch coordinates from server, parse them, and create ArrayList of Coordinates.
Coordinates:
- POJO for holding coordinates
Grid: JPanel
paintComponent(Graphics g)draws X and Y axes,drawCoordinates(Graphics g)draws Coordinates on screen
How would I go about fixing these artifacts, and making sure that when the app starts up the axes are drawn and the Coordinates are drawn once the fetching from the server is finished? I tried some stuff with synchronized but I'm not sure how that works with paintComponent(Graphics g) as that method isn't called explicitly in the code.
Thanks!!!