I realise this code looks, pointless, I’ve just got rid of the irrelevent stuff to show the structure
class Drawer extends JComponent {
public Drawer(int[] data) {
System.out.println("drawer");
for(int x = 0; x < data.length; x++){}
//work out what to draw
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
System.out.println("drawerpC"); //check to see if it is called
//draw stuff
}
}
In a separate file, a new instance of Drawer is called regularly. Every time it is called, data is different, and so every time Drawer is called, paintComponent needs to be called.
I have this code in that other file:
Drawer d = new Drawer(data);
myGUI.con.add(d); //myGUI.con is a previously set up container
repaint() is not causing paintComponent to be called (otherwise you’d see the stdout), so how can I force paintComponent to be called for every calling to Drawer?
Store the
int[]as a class attribute. Move//work out what to drawintopaintComponent(Graphics).