获取Runnable的当前实例 [英] Get current instance of Runnable

查看:189
本文介绍了获取Runnable的当前实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个允许用户查看存储在不同数据库中的任务列表的应用程序.所以发生的是,我有一个可浏览数据库的名称列表(存储为文本文件).程序在该列表中加载第一个数据库并显示内容.然后,从菜单中,我允许用户在列表中选择另一个数据库. (有点像,我想查看Andy的任务,现在是Bob的任务,现在是Carl的任务.).

I'm making an application that allows users to view task lists stored in different databases. So what happens is that, I have a list of the names of browsable databases (stored as a text file). Program loads the first database in that list and displays contents. Then from a menu, I allow users to select another database in the list. (Kind of like, I want to view the tasks for Andy, and now Bob, and now Carl...).

问题是,我不知道如何更新UI以便显示新数据库的内容.删除当前列出的任务,从数据库中读取,然后重新填充是很简单的.但是我无法(通过我的Singleton数据库驱动程序)获取此代码,因为我需要访问已加载到EventQueue的Runnable实例(我的所有JComponents都是私有的,就像我到目前为止遇到的所有教程一样) ).我正在查看EventQueue中的get/peek方法,但它们似乎不是我所需要的,因为它们返回AWTEvents,并且除java.lang.Object外,我没有看到AWTEvent与Runnable之间的任何关系.

Problem is, I don't know how to update the UI so that the contents of the new database is displayed. It's trivial to remove the tasks currently listed, read from the DB, and then repopulate. But I can't get to this code (from my Singleton database driver) because I would need access to the instance of my Runnable which was loaded to the EventQueue (all my JComponents are private, as with all tutorials I've so far encountered). I'm looking at the get/peek methods in EventQueue but they don't seem to be what I need since they return AWTEvents and I don't see any relation between AWTEvent and Runnable other than java.lang.Object.

那么,是否有可能获得当前的Runnable?怎么样?

So, is it possible to get the current Runnable? How?

提前感谢您的指导.

推荐答案

我怀疑您正在解决此错误.您要做的是从控件类中更改数据库(使用MVC命名法).例如,假设您将可用数据库加载到JList中,然后在该组件的控件中(例如ListSelectionListener),执行一个SwingWorker来加载新数据库,然后通过其发布/处理对在GUI中显示结果.方法或完成方法中.数据库代码(模型)应该对代码的视图或GUI部分(如您所称的Runnable)一无所知.

I suspect that you are going about this wrong. What you want to do is change databases from within a control class (using MVC nomenclature). For instance, say you load the available databases into a JList, then in the control for this component, say a ListSelectionListener, you execute a SwingWorker that loads the new database and then displays the results in the GUI either via its publish/process pair of methods or in the done method. The database code (the model) should know nothing about the view or GUI portion of your code (the Runnable as you call it).

这篇关于获取Runnable的当前实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆