如果这个问题的答案相当琐碎,请原谅我,因为我已经有一段时间没有编程了。我的应用程序的目标是从我在我的框架中显示的图像中获取 RGB 值,其中 (x,y) 坐标由鼠标侦听器给出,但是当我在我的事件处理程序中时,我只能访问x,y 值而不是我的 BufferedImage。帮助!我已经被困了好几个小时了!!
MouseHandler 类的代码:
public void mouseClicked (MouseEvent e)
{
int x = e.getX();
int y = e.getY();
System.out.printf("You clicked at: %d,%d\n", x, y);
}
应用程序类的代码:
public static void main(String args[])
{
String file_name = args[0];
BufferedImage image = readImage2(file_name);
Frame frame = createFrame(file_name);
//somehow get x,y from listener;
//int RGB = image.getRGB(x,y);
}