FileDocCategorySizeDatePackage
WebHunter.javaAPI DocExample2282Mon Jan 09 11:02:00 GMT 2006None

WebHunter

public class WebHunter extends JFrame implements ActionListener

Fields Summary
private Box
centerPane
private JTextField
sourceFile
Constructors Summary
public WebHunter()

    super("WebHunter");

    build();

    pack();
    setResizable(false);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
  
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent evt)

    URL source;
    try {
       source = new URL(sourceFile.getText());
    } catch (MalformedURLException me) {
       JOptionPane.showMessageDialog(this, "Invalid URL.", "Download error", JOptionPane.ERROR_MESSAGE);
       return;
    }

    JFileChooser chooser = new JFileChooser();
    chooser.setSelectedFile(new File(new File(source.getFile()).getName()));
    chooser.showSaveDialog(this);
    File target = chooser.getSelectedFile();

    JProgressBar bar;
    JPanel panel = new JPanel(new GridLayout(3, 2));  

    panel.add(new JLabel("Source: "));
    panel.add(new JLabel(sourceFile.getText()));
    panel.add(new JLabel("Target: "));
    panel.add(new JLabel(target.getAbsolutePath()));
    panel.add(new JLabel("Progress: "));
    panel.add(bar = new JProgressBar());
    panel.setBorder(new EmptyBorder(0, 3, 0, 3));
 
    bar.setStringPainted(true);
   
    centerPane.add(Box.createVerticalStrut(3));
    centerPane.add(new JSeparator());
    centerPane.add(Box.createVerticalStrut(3));
    centerPane.add(panel);
    centerPane.add(Box.createVerticalStrut(3));

    pack();
  
private voidbuild()

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(BorderLayout.NORTH,  buildDownloadPane());
    getContentPane().add(BorderLayout.CENTER, centerPane = Box.createVerticalBox());
  
private java.awt.ContainerbuildDownloadPane()

    JPanel panel = new JPanel();
    JButton button;

    panel.add(new JLabel("File to download: "));
    panel.add(sourceFile = new JTextField(15));
    panel.add(button = new JButton("Download..."));

    sourceFile.setText("http://jext.free.fr/macos7.jpg");
    button.addActionListener(this);

    return panel;
  
public static voidmain(java.lang.String[] args)

    new WebHunter();