⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webhunter.java

📁 《SWING HACKS》源码 作者: Joshua Marinacci,Chris Adamson 著 徐晔 译 出版: 2007年2月
💻 JAVA
字号:
import java.io.*;import java.net.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;public class WebHunter extends JFrame implements ActionListener {  private Box centerPane;  private JTextField sourceFile;  public WebHunter() {    super("WebHunter");    build();    pack();    setResizable(false);    setLocationRelativeTo(null);    setDefaultCloseOperation(EXIT_ON_CLOSE);    setVisible(true);  }  public void actionPerformed(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 void build() {    getContentPane().setLayout(new BorderLayout());    getContentPane().add(BorderLayout.NORTH,  buildDownloadPane());    getContentPane().add(BorderLayout.CENTER, centerPane = Box.createVerticalBox());  }  private Container buildDownloadPane() {    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 void main(String[] args) {    new WebHunter();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -