简体   繁体   English

ProgressMonitorInputStream无法正常工作?

[英]ProgressMonitorInputStream not working?

I am trying a simple socket based file transfer program to include a ProgressMonitorInputStream, my file transfer is working fine. 我正在尝试一个简单的基于套接字的文件传输程序,包含一个ProgressMonitorInputStream,我的文件传输工作正常。 But the progressMonitor never shows up. 但是progressMonitor从未显示。
I am sending a file from server to client, when it connects, my file is getting transfered perfectly, but just don't understand why the ProgressMonitor doesn't come up. 我正在从服务器向客户端发送文件,当它连接时,我的文件被完全转移,但只是不明白为什么ProgressMonitor没有出现。

I searched some examples, they used 'this' instead of 'new Jframe()' in PMIS, but since I was inside main(), it didn't allow me to do that. 我搜索了一些例子,他们在PMIS中使用'this'而不是'new Jframe()',但由于我在main()中,所以它不允许我这样做。

//client
InputStream is = sock.getInputStream();
BufferedInputStream bis = new BufferedInputStream(
new ProgressMonitorInputStream(new JFrame(),"reading",is));
while ((read = bis.read(buffer,0,buffer.length)) != -1) {
//read from socket...now write to file 
}    
I searched some examples, they used 'this' instead of 'new Jframe()' in PMIS

You have re_read tutorial about How to Use Progress Bars , there is basic description for ProgressMonitorInputStream 您有关于如何使用进度条的重新阅读教程,有ProgressMonitorInputStream的基本描述

Swing is single threaded and if you want to move with progress , then you have to redirect this Stream to the BackroundTask , tutorial about JProgressBar implelemnts SwingWorker , another options is wrap that to the Runnable#Thread , but in this case output to the GUI must be wrapped into invokeLater() Swing是单线程的 ,如果要随progress移动,则必须将此Stream重定向到BackroundTask ,有关JProgressBar符号SwingWorker的教程,另一个选择是将其包装到Runnable#Thread ,但在这种情况下,必须输出到GUI被包装到invokeLater()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM