📄 downloadactionlistener.java
字号:
/* * Copyright 2007 JavaAtWork All rights reserved. * Use is subject to license terms. */package com.javaatwork.mydownloader.listeners;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.JFileChooser;import javax.swing.JOptionPane;import com.javaatwork.mydownloader.DownloadFile;import com.javaatwork.mydownloader.MyDownloader;import com.javaatwork.mydownloader.dialog.CenteredFileChooser;import com.javaatwork.mydownloader.utils.LocaleManager;/** * Class which is responsible for downloading the files. * * @author Johannes Postma */public class DownloadActionListener implements ActionListener { private MyDownloader myDownloader = null; /** * Creates a new DownloadActionListener. This listener listens to * the download button. * * @param myDownloader The applet. */ public DownloadActionListener(MyDownloader myDownloader) { this.myDownloader = myDownloader; } /** * Will be invoked when the action has taken place. * * @param e The ActionEvent. */ public void actionPerformed(ActionEvent e) { // check if a file is selected final DownloadFile[] files = myDownloader.getFilesToDownload(); if (files == null || files.length == 0) { return; } CenteredFileChooser fileChooser = new CenteredFileChooser(); int returnValue = fileChooser.showSaveDialog(myDownloader); if (returnValue == JFileChooser.APPROVE_OPTION) { File directory = fileChooser.getSelectedFile(); if (!directory.exists()) { String message = LocaleManager.getInstance().getString("directory_does_not_exist"); message = message.replaceAll("<directory>", directory.toString()); myDownloader.showMessage(message, JOptionPane.INFORMATION_MESSAGE); } else { // download files DownloadManager downloadManager = new DownloadManager(); downloadManager.downloadFiles(myDownloader, directory); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -