MATLAB Answers

java.awt.Robot command and msgbox incompatability?

6 views (last 30 days)
Ryan on 2 Apr 2012
I had a function script that was working great. Part of it includes a little java.awt.Robot command that creates a custom mouse cursor. The script works exactly as I intended it to, without any bugs/errors so far as I can tell through repeated runnings.
However, I decided to add a msgbox command into the script, which gives the user running the program a couple instructions about what to do to run the program. Adding the msgbox command in seems to deactivate the java.awt.Robot command, even if I use various uiwait related workarounds.
Any idea what the problem is here? msgbox is overriding the Robot command I gave earlier in the function. Is the best option to:
-override msgbox? how do I do this? -use something besides msgbox for a pop-up text window, that won't interfere with java.awt.Robot? what's another option in MATLAB without going into a complicated route with subfigures and uicontrol text boxes?
For the record, here is the function in question (I put asterisks around the relevant parts of the code, that being the java.awt.Robot command and msgbox command for emphasis, they are obviously not part of the real function):
function START_Callback(a,b)
nRep = 1;
files = dir(fullfile(matlabroot,'toolbox','semjudge',bpic,'*.png'));
nFiles = numel(files);
combos = nchoosek(1:nFiles, 2);
index = combos(randperm(size(combos, 1)), :);
picture1 = files(index(nRep,1)).name;
picture2 = files(index(nRep,2)).name;
image1 = fullfile(matlabroot,'toolbox','semjudge',bpic,picture1);
image2 = fullfile(matlabroot,'toolbox','semjudge',bpic,picture2);
subplot(1,2,1); imshow(image1);
subplot(1,2,2); imshow(image2);
set(gcf,'Color',[1 1 1]);
uicontrol('Style', 'text',...
'Position', [200 375 200 20],...
'String','How related are these pictures?');
uicontrol('Style', 'text',...
'Position', [50 375 100 20],...
uicontrol('Style', 'text',...
'Position', [450 375 100 20],...
'String','Closely related');
nxt = uicontrol('Style','pushbutton','String','Next Trial',...
'Position', [250 45 100 20],...
**P = ones(16);
P(2:16,2:16) = NaN;
set(gcf, 'Pointer', 'custom','PointerShapeCData',P);
h = uicontrol(gcf,...
'Min' ,0,'Max',100, ...
'Position',[100 350 400 20], ...
'Value', 50,...
'SliderStep',[0.02 0.1], ...
'Callback', @SliderCallBackFcn);
set(gcf, 'WindowButtonMotionFcn', @point);
set(gcf, 'WindowScrollWheelFcn', @cb);
lastVal = get(h, 'Value');

  1 Comment

Jan on 2 Apr 2012
Please explain, what "seems to deactivate the java.awt.Robot command" exactly mean. I cannot guess this important detail.
It is recommended to post a small program only, which reproduces the problem. Posting unnecessary information discourage users from answering.

Sign in to comment.

Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!