如何在java中创建使用进度监视器的任务?
我创建了一个独立的java应用程序,我需要在其中将文件从一个地方复制到另一个地方。但是复制需要时间,我想在java中的进度监视器的帮助下显示复制的进度。进度监视器需要一个任务作为其参数,但我不知道如何为该复制功能创建任务。任何人都可以给我一些有关创建任务的代码或示例。
-提前致谢
I've created a stand alone java application in which i need to copy files from one place to other. But the copying takes times and i want to show the progress of the copying with the help of progress monitor in java. Progress Monitor requires a task as its parameter, but i do not know how to create a task for that copying function. Can anyone please give me some code or examples regarding creating a task.
-Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了为进度监视器创建任务,首先创建 swingworker 的子类,在其中提及要在 doInBackground() 方法中执行的代码。然后创建该类的对象并执行它。对于进度监视器,将 propertyChangeListener 添加到调用该对象的类,并将 ChangePropertyListener 添加到要为其创建进度监视器的特定对象。
有关详细信息,请查看此链接。
In order to create a task for a progress monitor first create a subclass of swingworker where you mention the code that is to be executed in the doInBackground() method. Then create an object of the class and execute it. For Progress Monitor add a propertyChangeListener to the class that calls the object and a changepropertyListener to that particular object for which you want to create the progress monitor.
For more info check this link.
Task 是 SwingWorker 的子类。阅读本教程。
Task is a subclass of SwingWorker. Read this tutorial.