我使用以下代码在 JPanel 上绘制了 BufferedImage。
protected void paintComponent(Graphics g) {
if (image != null) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
double x = (getWidth() - scale * imageWidth) / 2;
double y = (getHeight() - scale * imageHeight) / 2;
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.scale(scale, scale);
g2.drawRenderedImage(image, at);
}
}
如何向该图像添加鼠标单击侦听器?另外,我想获取图像的点击坐标,而不是 JPanel。