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

📄 frame1.java~6~

📁 简易多线程下载程序
💻 JAVA~6~
字号:
package mythead;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Frame1 extends JFrame {  JPanel contentPane;  String currentFileName;  String ipAddress;  String ipPort;  BorderLayout borderLayout1 = new BorderLayout();  JPanel jPanel1 = new JPanel();  XYLayout xYLayout1 = new XYLayout();  JPanel jPanel2 = new JPanel();  XYLayout xYLayout2 = new XYLayout();  JRadioButton jRadioButton1 = new JRadioButton();  JLabel jLabel1 = new JLabel();  JTextField jTextField1 = new JTextField();  JLabel jLabel2 = new JLabel();  JTextField jTextFieldIpProt = new JTextField();  JPanel jPanel3 = new JPanel();  XYLayout xYLayout3 = new XYLayout();  JTextField jTextFieldDownAddr = new JTextField();  JLabel jLabel3 = new JLabel();  JLabel jLabel4 = new JLabel();  JTextField jTextFieldThread = new JTextField();  JButton jButton1 = new JButton();  JProgressBar jProgressBar1 = new JProgressBar();  JLabel jLabel5 = new JLabel();  JTextField jTextFieldSaveAddr = new JTextField();  JButton jButton2 = new JButton();  JFileChooser jFileChooser1 = new JFileChooser();  //Construct the frame  public Frame1() {    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  //Component initialization  private void jbInit() throws Exception  {    contentPane = (JPanel) this.getContentPane();    contentPane.setLayout(borderLayout1);    this.setSize(new Dimension(400, 300));    this.setTitle("Frame Title");    jPanel1.setBackground(UIManager.getColor("InternalFrame.activeTitleGradient"));    jPanel1.setLayout(xYLayout1);    jPanel2.setBorder(BorderFactory.createEtchedBorder());    jPanel2.setLayout(xYLayout2);    jRadioButton1.setText("是否使用代理");    jLabel1.setText("地址:");    jTextField1.setText("");    jLabel2.setText("端口:");    jTextFieldIpProt.setText("");    jPanel3.setLayout(xYLayout3);    jLabel3.setText("下载地址:");    jTextFieldDownAddr.setText("");    jLabel4.setText("线程数:");    jPanel3.setBorder(BorderFactory.createEtchedBorder());    jButton1.setText("确定");    jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));    jProgressBar1.setMaximum(100);    jTextFieldThread.setText("");    jLabel5.setText("保存地址:");    jTextFieldSaveAddr.setText("");    jButton2.setText("浏览.....");    jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));    contentPane.add(jPanel1, BorderLayout.CENTER);    jPanel1.add(jPanel2,     new XYConstraints(4, 3, 393, 80));    jPanel2.add(jRadioButton1,   new XYConstraints(14, 6, 107, 23));    jPanel2.add(jLabel1,   new XYConstraints(20, 46, 48, 21));    jPanel2.add(jTextField1,  new XYConstraints(74, 45, 143, 24));    jPanel2.add(jLabel2,  new XYConstraints(229, 45, 55, 23));    jPanel2.add(jTextFieldIpProt,                                      new XYConstraints(265, 43, 70, 25));    jPanel1.add(jPanel3,    new XYConstraints(4, 85, 392, 210));    jPanel3.add(jTextFieldDownAddr,                                                                  new XYConstraints(72, 11, 306, 25));    jPanel3.add(jLabel3,  new XYConstraints(9, 9, 60, 28));    jPanel3.add(jButton1,    new XYConstraints(139, 168, 90, 30));    jPanel3.add(jLabel4,  new XYConstraints(11, 77, 56, 25));    jPanel3.add(jTextFieldThread, new XYConstraints(73, 78, 77, 26));    jPanel3.add(jTextFieldSaveAddr,      new XYConstraints(72, 44, 223, 25));    jPanel3.add(jLabel5,     new XYConstraints(9, 45, 60, 28));    jPanel3.add(jButton2,  new XYConstraints(309, 45, 68, 24));    jPanel3.add(jProgressBar1, new XYConstraints(5, 114, 380, 28));  }  //Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {    super.processWindowEvent(e);    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      System.exit(0);    }  }  void jButton2_actionPerformed(ActionEvent e) {    jFileChooser1.showSaveDialog(this);    currentFileName = jFileChooser1.getSelectedFile().getPath();    this.jTextFieldSaveAddr.setText(currentFileName) ;  }  void jButton1_actionPerformed(ActionEvent e) {    dai1=jTextField1.getText() ;  //  this.ipAddress=this.jtedai2=jTextField2.getText() ;currentFileName=jTextField3.getText() ;url1=jTextField4.getText() ;RandomAccessFile dst = null;try {  dst = new RandomAccessFile(currentFileName, "rw");}catch (FileNotFoundException ex) {}    System.getProperties().put("proxySet", "true");    System.getProperties().put("proxyHost", dai1);    System.getProperties().put("proxyPort", dai2);//http://www.nyist.net/nimages/barner1.giftry {    URL url = new URL(url1);    HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();    filelength = httpConnection.getHeaderFieldInt("Content-Length", -1);    httpConnection.disconnect();  }  catch (IOException ex) {}  int k=filelength/10;   hello h1[]=new hello[10];   for(int i=9;i>=0;i--){    h1[i]=new hello(url1,dst, i*k, i*k+k);    h1[i].start() ;      }  }}class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {  Frame1 adaptee;  Frame1_jButton2_actionAdapter(Frame1 adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton2_actionPerformed(e);  }}class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {  Frame1 adaptee;  Frame1_jButton1_actionAdapter(Frame1 adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton1_actionPerformed(e);  }}

⌨️ 快捷键说明

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