关闭

java多线程下载工具(三)

862人阅读 评论(3) 收藏 举报

3、JToolBar和JList的实现:

这两个的实现都相对与JTable的实现来说都比较简单,这里直接贴码。

JToolBar:

private void createBar() {
		// TODO Auto-generated method stub
		navJBar = new JToolBar();
		Action newTask = new AbstractAction("新建下载任务", new ImageIcon(
				"./images/tool/new-download.gif")) {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
			}
		};
		Action start = new AbstractAction("开始任务", new ImageIcon(
				"./images/tool/do-download.gif")) {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

			}
		};
		Action pause = new AbstractAction("暂停任务", new ImageIcon(
				"./images/tool/pause.gif")) {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

			}
		};
		Action delete = new AbstractAction("删除任务", new ImageIcon(
				"./images/tool/delete.gif")) {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

			}
		};
		Action deleteFinished = new AbstractAction("删除已经完成的任务", new ImageIcon(
				"images/tool/remove-finished.gif")) {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub

			}
		};
		this.navJBar.setFloatable(false);
		this.navJBar.add(newTask).setToolTipText("新建下载任务");
		this.navJBar.add(start).setToolTipText("开始任务");
		this.navJBar.add(pause).setToolTipText("暂停任务");
		this.navJBar.add(delete).setToolTipText("删除任务");
		this.navJBar.add(deleteFinished).setToolTipText("移除已经完成的任务");
		this.navJBar.setMargin(new Insets(5, 10, 5, 5));
		this.add(this.navJBar, BorderLayout.NORTH);
	}


JList

private void createList() {
		// TODO Auto-generated method stub
//		String[] jlistdata = { "文件大小:", "文件路径:", "下载时间:", "资源信息:" };
//		this.infoJList = new JList(jlistdata);

		 this.infoJList = new JList();
		 String FILE_SIZE_TEXT = "文件大小: ";
		 String FILE_PATH_TEXT = "文件路径: ";
		 String DOWNLOAD_DATE_TEXT = "下载时间: ";
		 String RESOURCE_INFO_TEXT = "资源信息: ";
		 ArrayList<Info> infoList = new ArrayList<Info>();
		 Info fileSize = new Info(FILE_SIZE_TEXT);
		 Info filePath = new Info(FILE_PATH_TEXT);
		 Info downloadDate = new Info(DOWNLOAD_DATE_TEXT);
		 Info info = new Info(RESOURCE_INFO_TEXT);
		 this.infoJList = new JList();
		 infoList.add(fileSize);
		 infoList.add(filePath);
		 infoList.add(downloadDate);
		 infoList.add(info);
		 this.infoJList.setListData(infoList.toArray());

	}


Info类代码:

public class Info {
	//对应的值
	private String value;
	public Info(String value) {
		this.value = value;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
	
	public String getValue() {
		return this.value;
	}
	
	public String toString() {
		return this.value;
	}

}


下面会继续更新悬浮窗口的实现

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:76325次
    • 积分:1795
    • 等级:
    • 排名:千里之外
    • 原创:102篇
    • 转载:3篇
    • 译文:1篇
    • 评论:9条
    最新评论