Java¿Î³ÌÉè¼Æ-FTP¿Í»§¶Ë-˵Ã÷Êé ÏÂÔر¾ÎÄ

¸½Â¼2: Ö÷ÒªÔ´³ÌÐò

(1) Ö÷½çÃæÀàFtp.java

public class Ftp extends JFrame {

FtpBean ftp=new FtpBean(); //FTP¿Í»§¶Ë¶ÔÏó private FileWriter write ; private PrintWriter out; private Date time;

private JTextField url = new JTextField(); //FTP·þÎñÆ÷µØÖ· private JTextField port = new JTextField(); //FTP·þÎñÆ÷¶Ë¿Ú private JTextField username = new JTextField(); //Óû§Ãû private JTextField password = new JTextField(); //ÃÜÂë private JTextField status = new JTextField(); //µ±Ç°×´Ì¬ private JButton connectButton=new JButton(\Á¬½Ó\); //Á¬½Ó°´Å¥ private JButton closeButton=new JButton(\¶Ï¿ªÁ¬½Ó\); //¶Ï¿ªÁ¬½Ó°´Å¥ private JPopupMenu popup = new JPopupMenu();//½¨Á¢Ò»¸öµ¯³öʽ²Ëµ¥ private JMenuItem refresh = new JMenuItem(\Ë¢ÐÂ\); //ÓÒ¼üµ¯³ö²Ëµ¥ private JMenuItem delete = new JMenuItem(\ɾ³ý\); private JMenuItem download = new JMenuItem(\ÏÂÔØ\); private JMenuItem upload = new JMenuItem(\ÉÏ´«\); private JMenuItem rename = new JMenuItem(\ÖØÃüÃû\); private JMenuItem upDir = new JMenuItem(\Éϼ¶Ä¿Â¼\);

private JMenuItem showLog = new JMenuItem(\ÏÔʾÈÕÖ¾ÐÅÏ¢\);

final DefaultListModel m=new DefaultListModel(); //ÏÔʾÎļþÁбí JList fileList = new JList(m); //ÉèÖÃÒ»×éÊý×é JScrollPane fileScrollPane;

private Dimension faceSize = new Dimension(400, 400); //¿ò¼Ü´óС public Ftp() {

init();

createPopup(); //µ¯³ö²Ëµ¥ time = new Date(); try {

write = new FileWriter(\,true); out = new PrintWriter(write,true); }

catch(IOException ioe) {

ioe.printStackTrace(); }

status.setEditable(false);

this.add(status,BorderLayout.SOUTH); //·ÅÖòÙ×÷ÐÅÏ¢ÏÔʾ°å

connectButton.addActionListener( new ActionListener() {

public void actionPerformed(ActionEvent e) {

connect(); } });

closeButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

close();

time = new Date();

out.println(time+\À뿪·þÎñÆ÷:\+url.getText()); } });

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Ìí¼Ó¿ò¼ÜµÄ¹Ø±Õʼþ´¦Àí this.pack();

this.setSize(faceSize); //ÉèÖÃÔËÐÐʱ´°¿ÚµÄλÖÃ

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation( (int) (screenSize.width - faceSize.getWidth()) / 2, (int) (screenSize.height - faceSize.getHeight()) / 2); this.setResizable(false);

this.setTitle(\¼òµ¥µÄFTP¿Í»§¶Ë\); //ÉèÖñêÌâ Image i=Toolkit.getDefaultToolkit().getImage(\); this.setIconImage(i); setVisible(true);

this.addWindowListener( //¹Ø±Õ³ÌÐòʱµÄ²Ù×÷ new WindowAdapter() {

public void windowClosing(WindowEvent e) {

close();

System.exit(0); } }

); }

void init() {

Container contentPane = getContentPane(); //»ñÈ¡Ãæ°å contentPane.setLayout(new BorderLayout()); //ÉèÖò¼¾Ö

JPanel up = new JPanel(); //ÉèÖÃÃæ°åÉÏ·½¿Ø¼þ²¼¾Ö up.setLayout(new GridLayout(3,2)); url.setText(\); port.setText(\);

username.setText(\);

password.setText(\);

JPanel no1 = new JPanel(); no1.setLayout(new BorderLayout());

no1.add(new JLabel(\·þÎñÆ÷:\),BorderLayout.WEST); no1.add(url,BorderLayout.CENTER);

JPanel no2 = new JPanel(); no2.setLayout(new BorderLayout());

no2.add(new JLabel(\¶Ë¿ÚºÅ:\),BorderLayout.WEST); no2.add(port,BorderLayout.CENTER);

JPanel no3 = new JPanel(); no3.setLayout(new BorderLayout());

no3.add(new JLabel(\̞:\),BorderLayout.WEST); no3.add(username,BorderLayout.CENTER);

JPanel no4 = new JPanel(); no4.setLayout(new BorderLayout());

no4.add(new JLabel(\ÃÜÂë :\),BorderLayout.WEST); no4.add(password,BorderLayout.CENTER); up.add(no1); up.add(no2); up.add(no3); up.add(no4);

up.add(connectButton); up.add(closeButton);

closeButton.setEnabled(false);

this.add(up,BorderLayout.NORTH); //ÉÏ·½ fileScrollPane = new JScrollPane(fileList,

JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

fileScrollPane.setPreferredSize(new Dimension(300,400)); this.add(fileScrollPane,BorderLayout.CENTER); //Öв¿ }

void createPopup()

{

refresh.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

update(); } });

popup.add(refresh);

delete.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

deleteFile(); } });

popup.add(delete);

download.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

downloadFile(); } });

popup.add(download);

upload.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

uploadFile(); } });

popup.add(upload);

rename.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

renameFile(); } });

popup.add(rename);