actionPerformed 可以返回值吗?
在我的应用程序中,我使用 FileChooser 来选择文件。所选文件的名称应返回给另一个类。如何在日食中做到这一点?
In my application I use a FileChooser to chose a file. The name of the selected file should be returned to another class. how to do this in eclipse?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当某些事件(例如单击按钮)时,actionPerformed 由事件调度线程调用,并且永远不应该直接调用它。如果您想要一个显示 FileChooser 并返回所选文件的方法,请声明另一个可以由 eventHandler 以及其他任何地方调用的方法:
actionPerformed is called by the event dispatch thread when some event (a button was clicked for instance) and it should never be invoked directly. If you want a method that shows a FileChooser and returns the selected file, then declare another method that can be called by an eventHandler as well as anywhere else:
查看 FileChooserDemo 和 FileChooserDemo2 此处 了解 FileChooser 的使用方法。
这是代码的相关摘录:
Have a look at FileChooserDemo and FileChooserDemo2 here for how FileChooser is used.
Here is a relevant excerpt of the code:
假设类“A”包含显示文件选择器的代码,而类“B”需要该值,则以下内容将满足您的需要。
Assuming class "A" contains the code to show the file chooser and class "B" needs the value, the following will do what you need.