how to declear global "import java.awt.Robot" and "import java.awt.event.*"?

조회 수: 4 (최근 30일)
hamze moosapour
hamze moosapour 2021년 12월 29일
댓글: Walter Roberson 2021년 12월 30일
I have some function contaning "import java.awt.Robot;" and "import java.awt.event.*;".
How can I define these two commands globally? So that I do not need to add these two commands separately in each function.
  댓글 수: 3
hamze moosapour
hamze moosapour 2021년 12월 29일
Thank you. in fact due to the many functions I wrote, this slows down the program in general. So if these two commands can be included in the main program that do not need to be run every time the program speed is greatly increased.
Geoff Hayes
Geoff Hayes 2021년 12월 29일
I'm surprised that these import commands are slowing down the program. Are you sure that they are the cause of the performance issues?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2021년 12월 30일
If such a global import is possible, it might destroy Matlab's stability. The imported functions without wildcards have a higher precedence than nested and local functions. With wildcards they are preferred to private functions also. So after a "global" import, all of Matlab's toolbox functions, which use function names, which match the imported functions by accident, will run unexpected code.
Therefore I assume, that such a global import is not possible. And if there is a method to do this, you should avoid it strictly, because it is a shot in your knee.
The import functions should not take a lot of time. For 1e6 calls I do not see a measurable effect. If you call a function much more often, check again, if it is really required to import the functions. Remember that you can call e.g. java.awt.Robot directly also without the need to import before. Creating such an object takes at least 10'000 times longer than importing the function, so if the code is slow, avoid to create the Robots repeatedly, but create one object and share it.
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 12월 30일
I could imagine import taking a notable amount of time in some cases, such as if the java class path included network folders.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Java from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by