Both answers are not correct (anymore?). You can assign the imported classes to a property of the classobject and access them without reimporting. The following code works just fine (tested in Matlab 2016a):
classdef moveAndClick < handle
properties (Access = private)
mouse;
leftClick;
end
methods
%% Constructor
function obj = moveAndClick()
import java.awt.Robot;
import java.awt.event.InputEvent;
obj.mouse = Robot;
obj.leftClick = InputEvent.BUTTON1_MASK;
end
%% Destructor
function delete (~)
end
function moveClick (obj, positionX, positionY)
% move mouse to requested position
obj.mouse.mouseMove(positionX, positionY);
% click on the current position
obj.mouse.mousePress(obj.leftClick);
obj.mouse.mouseRelease(obj.leftClick);
end
end
end