Search code examples
javaswingmatlabmouseeventfullscreen

get mouse position on full screen java image with matlab


It seems there not to be a method to show an image full screen with Matlab on Win8 64. So I found a solution somewhere using a java class, that is javax.swing.JFrame. I don't know java and more I cannot use Matlab command on java full screen image. My goal is to get the mouse cursor position on that image. Here is my code:

import java.awt.event.MouseEvent.*; %I tried also java.awt.event.* without results
import java.awt.Robot; %It doesn't seems to be useful

img=imread("my_image.tif");
jimg = im2java(img);
frame = javax.swing.JFrame;

mouse=java.awt.event.MouseEvent;  %here it doesn't work, the same if mouse=java.awt.event; 

frame.setUndecorated(true);
icon = javax.swing.ImageIcon(jimg);
label = javax.swing.JLabel(icon);
frame.getContentPane.add(label);
frame.pack;
screenSize = get(0,'ScreenSize'); 
frame.setSize(screenSize(3),screenSize(4));
frame.setLocation(0,0);
frame.show;

%what I need to make run but with the above definition it doesn't work
if mouse.getButton()
   [x,y]=mouse.getPoint();
end

I tried stupidly ginput but it creates another figure. This code shows correctly the full screen image but events about where I click, no. Matlab returns an error about mouse=java.awt.event.MouseEvent; definition. It reports: Undefined variable "java" or class "java.awt.event". The problem is the imported java classes, and maybe how I used them. How could I solve? I find everywhere but I didn't find any practical solution. Could you suggest any other solution, also without using java?


Solution

  • Simply I have to use the command:

    [A]=get(0,'PointerLocation')
    

    and in the matrix A I get the pointer position everywhere it is on screen, also on java frame image.