首页 > 解决方案 > 将参数传递给用 Jython 编写的 javafx 对象

问题描述

我在 Jython 中编写了一个对象来使用 javaFX 加载多个文件。由于结构非常“刚性”,我不知道如何在不破坏它的情况下将参数传递给这个对象。

import sys

from java.io import File
from java.nio.file import Paths
from javafx.application import Application
from javafx.stage import FileChooser, Stage


class fileBrowser(Application):
    @classmethod
    def main(cls):
        fileBrowser.launch(cls)

    @staticmethod
    def getAbsPath(primaryStage):
        fc = FileChooser()
        fc.setInitialDirectory(
            File(Paths.get(".").toAbsolutePath().normalize().toString())
        )
        return fc.showOpenMultipleDialog(primaryStage)

    def start(self, primaryStage):
        self.getAbsPath(primaryStage)


if __name__ == '__main__':
    fb = fileBrowser
    fb.main()

例如,我希望我可以将参数传递给函数 setInitialDirectory
然而,重要的是传递的任何参数都可以在 start 方法下进行
如果我使用构造函数def __init__(self),程序会中断。
所以我想知道...如何将参数传递给在 start 方法中读取的对象?
提前致谢!

标签: javaoopjavafxjython

解决方案


推荐阅读