简体   繁体   English

(Swing FEST)机器人是单例课程吗?

[英]is Robot (Swing FEST) a singleton class?

Recently I experienced that is a Robot instance is created already and if try to create it again (obviously without calling robot.cleanUp()) it hangs there forever. 最近,我经历了一个已经创建的Robot实例,如果尝试再次创建它(显然不调用robot.cleanUp()),它将永远挂在那里。 I investigated this and got to know that it takes a ScreenLock every time we create a Robot instance. 我对此进行了调查,并知道每次创建一个Robot实例都需要一个ScreenLock。

So my question is this kind of behaviour can be achieved by Singleton class. 所以我的问题是,这种行为可以通过Singleton类实现。 Then why we are allowed to create another Robot instance although it is a deadlock situation. 那么为什么我们仍然可以创建另一个Robot实例,尽管这是一个僵局。 I mean if I am to Create Robot, clean it up and create again then why should I clean and recreate it in the first place? 我的意思是,如果要创建机器人,请清理并再次创建,然后为什么要首先清理并重新创建它? There should be one API which will provide Robot instance upon user request because current approach does not make sense. 应该有一个可以根据用户请求提供Robot实例的API,因为当前的方法没有意义。

But, there is a constructor new Robot(GraphicsDevice screen), which creates a Robot instance with coordinate system relative to this screen. 但是,有一个新的构造函数Robot(GraphicsDevice屏幕),它创建一个具有相对于此屏幕的坐标系的Robot实例。 For this purpose it make sense to have multiple instances of Robot. 为此,具有多个Robot实例是有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM