如何在java中发送电子邮件时显示进度条
大家好 我想显示进度条 当我的程序发送电子邮件时
我该怎么做?
hii every one
I want to show progress bar
while my program sends email
how can i do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
显示带有沙漏或条纹加载栏或类似内容的简单 gif 图像。由于这将是单步操作,因此您实际上无法告诉用户 N% 已完成。添加带有超时的回调来验证操作是否成功。显示图像的方式取决于您使用的技术。
Display a simple gif image with hourglass or striped loading bar or something similar. Since this will be a single step operation you can't actually tell the user N % complete. Add a callback with timeout to verify the success of the operation. How you display the image depends on what technology you are using.
Swing 的 JProgressBar 可能是小程序的最佳选择。
当您不知道操作需要多长时间时,它有一个模式。
对于 JavaMail,您可以使用 TransportListener 监听传输系统(可能是 com.sun.mail.smtp.SMTPTransport),它会告诉您至少每封邮件何时发送,这样您就可以为多个收件人执行进度。
Swing's JProgressBar is probably your best bet for an applet.
It has a mode for when you don't know how long an operation will take.
For JavaMail you can listen to the transport system (probably com.sun.mail.smtp.SMTPTransport) with a TransportListener which will tell you when each message has been sent at least, so you can do progress for multiple recipients.
您需要将两个类放在一起, JProgressBar< /a> 用于 UI,以及 SwingWorker 用于后台线程。从您的评论来看,您首先需要查看 SwingWorker 教程。
You need to put together two classes, JProgressBar for the UI, and SwingWorker for the background thread. From your comments, it looks like you first need to be looking at a SwingWorker tutorial.
根据本机/网络应用程序、单个电子邮件/多个电子邮件,解决方案可能略有不同。
例如,Web 应用程序+单个电子邮件,请考虑使用动画 gif,同时在另一个 iframe 中发送电子邮件。
例如webapp+多封邮件,每封邮件发送后,进度条可以根据已发送邮件数/邮件总数,持续显示完成百分比。
depending on native/webapp, single email/multiple emails, solutions might be slightly different.
e.g webapp+single email, consider a animated gif, while you do send the email in another iframe.
e.g. webapp+multiple email, a progress bar can continuously display the percentage done, based on a number of sent emails/total emails, after each email get sent.