管理函数main

I created a class A that reads a text file and alters some lines within the text, and the code is written in main() of this class. I also created another class B that has a Frame, the Frame contains a list of text files of a directory and a button. What I don't know how to do is this: When I click on the selected item on the list and click the button, the function main is called and the selected item is being read by main().

Any suggestion is welcomed and thanks in advance.

#0

When you have code in the static main method, you have a non-object oriented code block, one that won't easily be used by other object oriented-compliant portions of your program. The best solution here is to get all code but the minimal out of main and create a true OOP-compliant class, one that can be more easily used by your other classes.

Your other issue is the mixing of your text-processing code with your GUI code, and this may require further fixing, especially if the text-processing code takes a while to complete or is a CPU hog. If so, you'll need to take care to do the text-processing in a thread that is background to the GUI thread, and again, this is much more easily performed if the text-processing code is in a well-behaved OOP class.

#1

The main method is just like any other method, you call it the same way.

class A {
    public static void main(String... args) {
        String filename = args[0];
    }
}

class B {
    public void onFilename(String filename) {
        A.main(filename);
    }
}

You might want to use a background thread instead of locking up the GUI while it is processing. ;)

推荐文章

在jqGrid中启用虚拟滚动时预加载页面

在jqGrid中启用虚拟滚动时预加载页面

推荐文章

是否可以设置在使用EvoPDF导出页面时使用的呈现引擎

是否可以设置在使用EvoPDF导出页面时使用的呈现引擎

推荐文章

jQuery UI对话框-停止关闭事件

jQuery UI对话框-停止关闭事件

推荐文章

用php生成随机数并提交到数据库

用php生成随机数并提交到数据库

推荐文章

休眠分配不正确的数据库ID

休眠分配不正确的数据库ID

推荐文章

Selenium IDE-将默认速度设置为慢速

Selenium IDE-将默认速度设置为慢速

推荐文章

为什么jqGrid cellattr样式在IE7中似乎不起作用(但在IE8和FF中效果很好)

为什么jqGrid cellattr样式在IE7中似乎不起作用(但在IE8和FF中效果很好)

推荐文章

wxPython窗口无法关闭

wxPython窗口无法关闭

推荐文章

什么使参数成为事件对象?

什么使参数成为事件对象?

推荐文章

使列以空标题扩展到浏览器底部,并使用最小高度

使列以空标题扩展到浏览器底部,并使用最小高度

推荐文章

使用Fog和Carrierwave对上载的文件进行粒度“public”设置

使用Fog和Carrierwave对上载的文件进行粒度“public”设置

推荐文章

移除iframe周围多余的空白?

移除iframe周围多余的空白?

推荐文章

如何批量加密MySQL数据库中的现有密码?

如何批量加密MySQL数据库中的现有密码?

推荐文章

单击浏览器[上一步]按钮后还原会话变量

单击浏览器[上一步]按钮后还原会话变量

推荐文章

带多窗口处理的WPF+MVVM

带多窗口处理的WPF+MVVM

推荐文章

从我的应用程序运行另一个android应用程序?

从我的应用程序运行另一个android应用程序?