I am writing a simple population model in scala. I want to model each species with a different colored dot and output (in the gui…I’m using scala swing) a continuous display of each instances position. The animals are free to move and can multiply, eat each other, etc.
How exactly do I output this continuous display? I can do buttons and layouts in swing but this idea of a continuous display screen is foreign to me
You can create a custom component by extending
JPaneland overridepaintComponent(Graphics g)where you implement the drawing of your colored dots.See Trail: 2D Graphics and Lesson: Getting Started with Graphics for more information about Java 2D graphics API.
To continuosly update the panel, you can use a Swing Timer to update it in intervals: