• 大小: 22KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: Java
  • 标签:

资源简介

多线程-断点续传下载工具 功能描述: 实现同时下载多个文件,下载的过程中可以临时终止下载,可以随时继续下载。 该源码全是干货。核心源码一幕了然。

资源截图

代码片段和文件信息

package Download;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.objectInputStream;
import java.io.objectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class Downloadframe extends Jframe {
    private static final int THREAD_NUM = 4;
    private List itemList = new ArrayList();
    private transient InnerThread innerThread = new InnerThread();
    private static final String downloadInfoFile = “downloadInfo“;
    public Downloadframe() {
        setSize(500 400);
        add(createContentPane());
        setLocationRelativeTo(null);
        setResizable(false);
        setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
    }
    public void init() {
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                if (itemList != null && itemList.size() > 0) {
                    for (DownloadItem item : itemList) {
                        if (item.status == DownloadItem.STATUS_START) {
                            item.stop();
                        }
                    }
                }
                save(Downloadframe.this);
            }
        });
        if (itemList != null && itemList.size() > 0) {
            for (DownloadItem item : itemList) {
                item.setActionListener();
            }
        }
        innerThread = new InnerThread();
        innerThread.start();
    }
    private Component createContentPane() {
        JPanel p = new JPanel(new BorderLayout());
        p.setBackground(new Color(35 31 32));
        p.add(BorderLayout.CENTER createTabPane());
        return p;
    }
    private JPanel createTabPane() {
        JPanel p = new JPanel(new GridLayout(10 1 6 6));
        p.setBackground(new Color(35 31 32));
        p.setBorder(new EmptyBorder(8 8 8 8));
        for (int i = 0; i < THREAD_NUM; i++) {
            DownloadItem item = new DownloadItem();
            // label
            JLabel label = new JLabel();
            label.setForeground(Color.WHITE);
            item.label = label;
            // button
            JButton btn = new JButton();
            btn.setForeground(new Color(249 250 251));
            btn.setBackground(new Color(220 31 36));
            item.button = btn;
            // progressPanel
            ProgressPanel pp = new ProgressPanel();
            item.progressPanel = p

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-09-28 15:44  Download\
     文件         226  2013-08-31 22:37  Download\.classpath
     文件         367  2013-08-31 22:38  Download\.project
     目录           0  2014-09-28 15:44  Download\.settings\
     文件         110  2013-09-13 00:23  Download\.settings\org.eclipse.core.resources.prefs
     目录           0  2014-09-28 15:44  Download\bin\
     目录           0  2014-09-28 15:44  Download\bin\Download\
     文件        1259  2014-06-24 17:40  Download\bin\Download\Downloadframe$1.class
     文件        2156  2014-06-24 17:40  Download\bin\Download\Downloadframe$DownloadItem$1.class
     文件        2736  2014-06-24 17:40  Download\bin\Download\Downloadframe$DownloadItem.class
     文件        1051  2014-06-24 17:40  Download\bin\Download\Downloadframe$InnerThread.class
     文件         908  2014-06-24 17:40  Download\bin\Download\Downloadframe$ProgressPanel.class
     文件        5252  2014-06-24 17:40  Download\bin\Download\Downloadframe.class
     文件        2005  2014-06-24 17:40  Download\bin\Download\DownloadInfo.class
     文件        2861  2014-06-24 17:40  Download\bin\Download\DownloadThread.class
     文件         372  2013-08-31 22:48  Download\bin\readme
     文件       13122  2014-06-24 17:41  Download\downloadInfo
     目录           0  2014-09-28 15:44  Download\src\
     目录           0  2014-09-28 15:44  Download\src\Download\
     文件        8690  2013-09-03 17:09  Download\src\Download\Downloadframe.java
     文件        1869  2013-09-03 17:08  Download\src\Download\DownloadInfo.java
     文件        2073  2013-09-03 17:08  Download\src\Download\DownloadThread.java
     文件         372  2013-08-31 22:48  Download\src\readme

评论

共有 条评论

相关资源