%% SL. 12
function myButtonRandColor()
%% function generating GUI and defines callback function
hFig = uifigure('Position',[500 500 500 50], ...
   'Resize', 'off');
hLabel = uilabel(hFig, 'Text', 'yellow', ...
   'Position', [0 0 250, 50], ...
   'HorizontalAlignment', 'center');
hButt = uibutton(hFig, 'Text', 'my button', ...
   'Position', [250 10 250 30], ...
   'BackgroundColor', 'y');

hButt.ButtonPushedFcn = @(scr, event)changeColor(hButt, hLabel);
end

function changeColor(hButt, hLabel)
Color = rand(1,3);
hButt.BackgroundColor = Color;
hLabel.Text = sprintf('[R:%0.4f, G:%0.4f,B:%0.4f]', Color);
end

%% SL. 14
function mousePosition()
hFig = uifigure('Position', [200, 200, 200, 350]);
hText = uilabel(hFig, 'Position', [0, 150, 200, 50], ...
   'FontSize', 15, 'BackgroundColor', 'w', ...
   'HorizontalAlignment', 'center');

hFig.WindowButtonMotionFcn = ...
   @(src, event)moveFcn(hFig, hText);
end

function moveFcn(hFig, hText)
mousePos = get(hFig, 'CurrentPoint');
hText.Text = ...
   sprintf('x:%3.0f | y:%3.0f', mousePos);
end

%% SL. 15
function keyboardScan()
hFig = uifigure('Position', [200, 200, 200, 350]);
hText = uilabel(hFig, 'Position', [0, 150, 200, 50], ...
   'FontSize', 30, 'BackgroundColor', 'w', ...
   'HorizontalAlignment', 'center', ...
   'Text', '');

hFig.WindowKeyPressFcn = ...
   @(src, event)keyFcn(hText, event);
end

function keyFcn(hText, event)
hText.Text = sprintf('%s', event.Key);
end
