package ch11;import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
[code=Java]
//本类写了MyXunlei的界面和监听响应
//定义类MyXunlei,继承JFrame类,实现ActionListener接口
public class MyXunlei extends JFrame implements ActionListener
{

//定义界面需要的面板、文本框、按钮、进度条、复选框等
private JPanel contentPane;
private JPanel progressPane;
private JTextField textField1=new JTextField();
private JTextField textField2=new JTextField();
private JButton downLoadButton=new JButton("下载");
private JButton openButton = new JButton("打开");
private JButton stopButton = new JButton("停止");
private JComboBox nThreadBox;
private JCheckBox proxybutton = new JCheckBox();
private JLabel label1=new JLabel();
private JLabel label2=new JLabel();
private JLabel label3=new JLabel("设置代理 : ");
private JLabel label4=new JLabel("下载进度:");
private JLabel label5=new JLabel("线程数:");
private JTextArea textArea=new JTextArea();
private JProgressBar jProgressBar = new JProgressBar();
private int nTread = 5;
static String host = "";
static String port = "";
DownLoadFile downFile;

public MyXunlei()
{
//定义组件的默认值,标题、大小、位置,添加监听,并将组件添加到相应的容器中
contentPane = (JPanel)this.getContentPane();
contentPane.setLayout(null);//设置面板布局为空布局
//设置默认下载地址
textField1.setText("http://www.itxx8.cn/DT_downsoft/MyXunlei.java");
textField2.setText("d:\\MyXunlei.java");//设置默认保存地址
textField1.setBounds(150,200,200,20);//设置位置、大小
textField2.setBounds(150,240,120,20);//设置位置、大小
label1.setText("下载的目标文件为: ");//设置标签文本
label2.setText("下载的文件另存为: ");
label1.setBounds(20,200,120,20);
label2.setBounds(20,240,120,20);
openButton.addActionListener(this);//添加监听器
openButton.setBounds(280, 240, 60, 20);
downLoadButton.addActionListener(this);
downLoadButton.setBounds(20,280,60,20);
stopButton.addActionListener(this);
stopButton.setBounds(100, 280, 60, 20);
label3.setBounds(165, 280, 80, 20);
proxybutton.setBounds(225, 280, 20, 20);
proxybutton.addActionListener(this);
nThreadBox= new JComboBox(new String[]{"1","2","3","4","5","6","7","8","9","10"});
label5.setBounds(250, 280, 60, 20);
nThreadBox.setBounds(300, 280, 40, 20);
nThreadBox.addActionListener(this);
//将组件添加到面板容器中
contentPane.add(textField1);
contentPane.add(textField2);
contentPane.add(label1);
contentPane.add(label2);
contentPane.add(openButton);
contentPane.add(downLoadButton);
contentPane.add(stopButton);
contentPane.add(label3);
contentPane.add(proxybutton);
contentPane.add(label5);
contentPane.add(nThreadBox);
textArea.setEnabled(false);//设置文本区不能编辑
textArea.setForeground(Color.black);//设置前景颜色
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setBounds(20,20,330,170);
contentPane.add(scrollPane,null);
progressPane = new JPanel();
progressPane.setBounds(20, 320,330,100);
progressPane.add(label4);
progressPane.add(jProgressBar);
contentPane.add(progressPane);
this.setTitle("我的迅雷");//设置标题
this.setBounds(200, 200, 380, 400);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);//设置关闭动作
}

//重写actionPerformed方法,为每个按钮、复选框添加响应
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == openButton)
{//按下打开按钮时,显示文件选择对话框
JFileChooser fc=new JFileChooser();
if(fc.showSaveDialog(this)==fc.APPROVE_OPTION)
{
File f=fc.getSelectedFile() ;
textField2.setText(f.getAbsolutePath()) ;
}
}
if(e.getSource() == downLoadButton)
{//按下下载按钮时,开始下载,如果地址和保存路径为空,给出提示
String URL = textField1.getText();
String saveURL = textField2.getText();
if(URL.compareTo("")==0 && saveURL.compareTo("")==0)
{
textArea.setText("请输入要下载的文件和保存文件完整地址");
}
else
{
try
{
downFile=new DownLoadFile(URL,saveURL,textArea,nTread,jProgressBar);
downFile.start();
textArea.append("主线程启动……");
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
if(e.getSource() == nThreadBox)
{//如果选择线程数,相应改变当前的线程数
String item = nThreadBox.getSelectedItem().toString();
System.out.println("item is :"+item);
nTread = Integer.parseInt(item);
}
if(e.getSource() == stopButton)
{//如果按下停止按钮,停止下载
downFile.stop();
textArea.append("\n 停止下载!!");
}
if(e.getSource() == proxybutton)
{//选择或取消代理服务器
if(proxybutton.isSelected())
{
textArea.append("\n 代理服务被选择");
Point point=this.getLocation();
int x = this.getHeight()/2+point.x;
int y = this.getWidth()/2+point.y;
ProxyPanel proxypanel=new ProxyPanel(x,y);
}else
{
   textArea.append("\n 取消代理服务");
   System.getProperties().clear();
}
}
}
//主方法
public static void main(String[] args)
{//创建MyXunlei对象,运行程序
MyXunlei download = new MyXunlei();
}
}
 [/code]还有代码2,请搜素代码2的帖子“我的迅雷程序加速问题(code2)”