How to pan an image using your mouse in Java Swing

前端 未结 3 473
逝去的感伤
逝去的感伤 2020-12-31 23:55

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

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-01 00:10

    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).

提交回复
热议问题