I am creating a Java app that will allow users to view images and to pan the image using their mouse. To implement the panning of the image I use a combination of mous
I would do it in a different way. I would probably define an object called Image
or similar. It would define a BufferedImage
and two int
values: x
and y
.
The Image
object would also have a draw()
method that would just know how to draw an image to a Graphics2D
object at the x, y
location.
On mouse events, I would modify the x
and y
values inside the Image
object and under the paint
of the component I would call image.draw(g2)
.