使用单独的线程类填充 SWT 表对象

发布于 2024-08-25 05:41:49 字数 854 浏览 8 评论 0原文

我有一个代码片段 由 swt 团队开发,它正是我所需要的。但是,我想将一部分分成另一个类,特别是整个内联内容。为了回答我的前一个问题,有人建议应使用 Callable为了实现线程对象。建议使用可运行或更好可调用的实现,因为我确实需要某种返回。

但是,我不明白。我的问题是:

  1. 在原始代码中,在方法 run 的内联实现中,调用了一些父对象。当线程分离时我该怎么做?通过 C'tor 的参数传递对象?
  2. 在原始代码中,另一个可运行对象嵌套在可运行实现中。它有什么用呢?分离代码后如何实现this?此外,这个嵌套的可运行对象再次调用由 main 方法创建的对象。

请怜悯我,但我仍然是一个初学者,我的大脑快要崩溃了:-(我想要的就是将所有线程的东西分离到另一个类中,并使程序执行与它已经执行的操作相同的操作。请帮忙!

再次非常感谢您提供任何有用的建议、提示、示例等...

Regs 我

I've got a code snippet by the swt team that does exactly what I need. However, there is a part I want to separate into another class, in particular, the whole inline stuff. In response to my former question, it has been suggested that Callable should be used in order to implement threaded objects. It is suggested to make use of an implementation of runnable or better callable, since I do need some kind of return.

However, I don't get it. My problems are:

  1. In the original code, within the inline implementation of the method run, some of the parents objects are called. How would I do this when the thread is separated? Pass the object via the C'tor's parameter?
  2. In the original code, another runnable object is nested within the runnable implementation. What is it good for? How to implement this when having separated the code? Furthermore, this nested runnable again calls objects created by the main method.

Please, have mercy with me, but I am still quite a beginner and my brain is near collapsing :-( All I want is to separate all the threaded stuff into another class and make the program do just the same thing as it already does. Help please!

Again thank you very much in advance for any useful suggestions, hints, examples etc...

Regs
Me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁〃客ぐ 2024-09-01 05:41:49

java中的内部非静态类接收父实例(对于非静态方法)以及它们在构造函数中需要的所有最终局部变量(和方法参数)。您可以自己实现这种方法 - 这对于大型班级来说是可以的。

所有 UI 内容都必须在主线程中执行。这就是使用嵌套 Runnable 对象的原因。它被 display.syncExec 添加到事件队列中,然后主线程在某个时候提取它并执行它的 run 方法。如果你想在这里创建单独的类,你应该通过构造函数或 setXXX 方法传递参数。

The inner non-static classes in java receive parent instance (for non-static methods) and all final local variables (and method params) they need in the constructor. You can implement this approach yourself - this is ok for large classes.

All UI stuff must be executed in the main thread. That's why nested Runnable object is used. It is added to the event queue by display.syncExec then main thread extracts it somewhen and executes its run method. If you want to create separate class here, you should pass params via constructors or setXXX methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文