使用 MouseMotionListener 在 heatMap 上进行双矩阵坐标

Double Matrix coordinates over heatMap using MouseMotionListener

我有一个双矩阵,我使用 HeatMap class ( http://www.mbeckler.org/heatMap/). I use MouseMotionListener to get the mouse position when it is hovered over the image. Since the actual heatmap is smaller than the HeatMap panel, I set coordinate bounds for getting the mouse coordinate position (Previous question for details: )

为其构建了一个热图

跟踪鼠标移动的鼠标事件如下所示:

public void mouseMoved(MouseEvent e) {
        if(e.getPoint().x  >= 31 && e.getPoint().y >= 31 && e.getPoint().x <= intensityMap.getWidth()-31 && e.getPoint().y <= intensityMap.getHeight()-31) {

            int maxX = (intensityMap.getWidth() - 31)-31;
            int maxY = (intensityMap.getHeight() - 31)-31;
            intensityMap.add(coordinates);
            coordinates.setText("(x,y) = " + "(" + (e.getPoint().x - 31) + "," +     (e.getPoint().y - 31) + ")");
            coordinates.revalidate();
            coordinates.repaint();
        }
    }

现在,我想将这些鼠标坐标位置转换为用于绘制热图的双矩阵的坐标位置。根据鼠标事件的总行数为 235,总列数为 128。双矩阵的维度为 37,32。如何将双矩阵的坐标映射到热图上?

This 可能会有帮助。您需要以某种方式将矩阵映射到 JPanel 对象。