I got some interesting ideas and criticism from this, this and this post (see last post for the code of the GUI in question). Nevertheless, I'm still quite confused about some things. Mainly, what is the least expensive way of displaying user-introduces graphics?
More specifically, I used a paintComponent()
method from JPanel
class by making an object of this class in the MouseDragged()
method together with paintComponent(getGraphics())
method (AuxClass2
and AuxClass1
accordingly).
Apparently, using getGraphics()
and paintComponent()
instead of repaint()
are bad ideas, I suspect something to do with memory use. Also calling the AuxClass2
every time the user drags the mouse is also a bad idea.
Also JPanel vs Canvas (i.e. swing vs awt) is a bit confusing. What is used and when?
I've been trying to find a workarounds, but have not found one, especially for the getGraphics()
method: how else can the graphics be added to the panel?