1

我有一个运行良好的函数脚本。其中一部分包括一个创建自定义鼠标光标的小 java.awt.Robot 命令。该脚本完全按照我的预期工作,没有任何错误/错误,据我可以通过重复运行判断。

然而,我决定在脚本中添加一个 msgbox 命令,它为运行程序的用户提供了一些关于如何运行程序的说明。添加 msgbox 命令似乎会停用 java.awt.Robot 命令,即使我使用各种与 uiwait 相关的解决方法。

知道这里有什么问题吗?msgbox 覆盖了我之前在函数中给出的 Robot 命令。是最好的选择:

-覆盖msgbox?我该怎么做呢?- 使用 msgbox 之外的其他内容作为弹出文本窗口,不会干扰 java.awt.Robot?MATLAB 中的另一个选项是什么,而不需要进入带有子图和 uicontrol 文本框的复杂路径?

作为记录,这里是有问题的函数(我在代码的相关部分周围加上了星号,即 java.awt.Robot 命令和 msgbox 命令用于强调,它们显然不是真正函数的一部分):

function START_Callback(a,b)
delete(gcf);

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],...
'String','Unrelated');
uicontrol('Style', 'text',...
'Position', [450 375 100 20],...
'String','Closely related');
nxt = uicontrol('Style','pushbutton','String','Next Trial',...
'Position', [250 45 100 20],...
'Callback',{@NextTrial});

set(nxt,'Enable','off');

**P = ones(16);
P(2:16,2:16) = NaN;
set(gcf, 'Pointer', 'custom','PointerShapeCData',P);
jRobot=java.awt.Robot;
x=928;
y=457;
jRobot.mouseMove(x,y);**

h = uicontrol(gcf,...
'Style','slider',...
'Min' ,0,'Max',100, ... 
'Position',[100 350 400 20], ... 
'Value', 50,...
'SliderStep',[0.02 0.1], ...
'BackgroundColor',[0.8,0.8,0.8],...
'Callback', @SliderCallBackFcn);

set(gcf, 'WindowButtonMotionFcn', @point);

set(gcf, 'WindowScrollWheelFcn', @cb);

**msgbox('INSTRUCTIONS GO HERE');**

lastVal = get(h, 'Value');

end
4

0 回答 0