日期:2014-05-20  浏览次数:20700 次

求助啦~~为什么点击其中的按钮都没反应~~
/*
 * Main.java
 *
 * Created on 2007年12月19日, 下午8:35
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
import sun.net.ftp.*;
import sun.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
public class UseFTP extends JFrame implements ActionListener{

FtpClient aftp;
DataOutputStream outputs; //数据输出流
TelnetInputStream ins; //输入流
TelnetOutputStream outs; //输出流
JTextArea lsArea=new JTextArea(40,100);
JLabel lblPrompt =new JLabel("没有连接主机",Label.LEFT);
JLabel lblHost =new JLabel("主机名:");
JLabel lblUID =new JLabel("用户名:");
JLabel lblPWD =new JLabel("密码:");
JLabel lblFile =new JLabel("要下载的文件名:");
JLabel lblDir =new JLabel("存放文件的路径:");
JButton btnConn=new JButton("连接");
JButton btnClose=new JButton("断开");
JButton btnDown=new JButton("下载");
JButton btnUp=new JButton("上传");
JTextField txtHost=new JTextField(34);
JTextField txtUID=new JTextField(14);
JPasswordField txtPWD=new JPasswordField(14);
JTextField txtDir=new JTextField(29);
JTextField txtFile=new JTextField(29);
int ch;
String a="没有连接主机";
String hostname="";

public UseFTP(){
  JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT));
  JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT));
  JPanel p3=new JPanel(new FlowLayout(FlowLayout.LEFT));
  btnClose.enable(false);
  p1.add(lblPrompt);
  p2.add(lblHost);p2.add(txtHost);p2.add(btnConn);
  p3.add(lblUID);p3.add(txtUID);p3.add(lblPWD);
  p3.add(txtPWD);p3.add(btnClose);
   
  JPanel top =new JPanel(new GridLayout(3,1));
  top.add(p1);top.add(p2);top.add(p3);
  lsArea.setEditable(false);
  JScrollPane jsp=new JScrollPane(lsArea);
  JPanel bottom=new JPanel(new GridLayout(2,1));
  JPanel p4=new JPanel(new FlowLayout(FlowLayout.LEFT));
  JPanel p5=new JPanel(new FlowLayout(FlowLayout.LEFT));
  p4.add(lblFile);p4.add(txtFile);p4.add(btnUp);
  p5.add(lblDir);p5.add(txtDir);p5.add(btnDown);
  bottom.add(p4);bottom.add(p5);
  this.getContentPane().add(top,"North");
  this.getContentPane().add(jsp,"Center");
  this.getContentPane().add(bottom,"South");
  this.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){
  try{aftp.closeServer();
  }catch(Exception ee){}
  dispose();
  System.exit(0);
  }
  });
  setSize(520,400);
  setTitle("FTP客户端");
  setVisible(true);
}
public boolean connect(String hostname,String uid,String pwd){ //连接函数
this.hostname =hostname;
lblPrompt.setText("正在连接,请等待……");
try{
  aftp=new FtpClient(hostname);
  aftp.login(uid,pwd);
  aftp.binary();
  showFileContents();
}
catch(FtpLoginException e){
lblPrompt.setText("无权限与主机:"+hostname+"连接!");
return false;
}
catch(IOException e){
lblPrompt.setText("连接主机:"+hostname+"失败!");
return false;
}
catch(SecurityException e){
lblPrompt.setText("无权限与主机:"+hostname+"连接!");
return false;
}
lblPrompt.setText("连接主机:"+hostname+"成功!");
return true;
}
public void actionPerformed(ActionEvent e){ //点击按钮相应的响应