1

うまく機能する関数スクリプトがありました。その一部には、カスタム マウス カーソルを作成する小さな java.awt.Robot コマンドが含まれています。スクリプトは、繰り返し実行してわかる限り、バグやエラーなしで、意図したとおりに機能します。

しかし、スクリプトに msgbox コマンドを追加することにしました。これにより、プログラムを実行しているユーザーは、プログラムを実行するために何をすべきかについていくつかの指示を得ることができます。msgbox コマンドを追加すると、さまざまな uiwait 関連の回避策を使用しても、java.awt.Robot コマンドが無効になるようです。

ここで何が問題なのか分かりますか?msgbox は、関数の前半で指定した Robot コマンドをオーバーライドしています。次の場合に最適なオプションです。

-メッセージボックスを上書きしますか? どうすればいいですか?- java.awt.Robot に干渉しない、ポップアップ テキスト ウィンドウ用の msgbox 以外のものを使用しますか? サブフィギュアと uicontrol テキスト ボックスを使用して複雑なルートに入る必要のない MATLAB の別のオプションは何ですか?

記録として、問題の関数は次のとおりです (コードの関連部分を強調するためにアスタリスクで囲んでいますが、これらは明らかに実際の関数の一部ではありません)。

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