当前位置: 技术问答>java相关
//super 指代什么??附源代码一个ftp粘贴程序
来源: 互联网 发布时间:2017-04-22
本文导语: package ftpapplet; import java.awt.*; import java.awt.event.*; import java.applet.*; /** * Title: * Description: * Copyright: Copyright (c) 2002 * Company: * @author unascribed * @version 1.0 */ //package jdeveloper.ftp; import sun.net.ftp.*; i...
package ftpapplet;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/**
*
*
*
*
* @author unascribed
* @version 1.0
*/
//package jdeveloper.ftp;
import sun.net.ftp.*;
import sun.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
public class FtpApplet extends Applet
{
FtpClient aftp;
DataOutputStream outputs;
TelnetInputStream ins;
TelnetOutputStream outs;
TextArea lsArea;
Label LblPrompt;
Button BtnConn;
Button BtnClose;
TextField TxtUID;
TextField TxtPWD;
TextField TxtHost;
int ch;
public String a="cannot connect to Host";
String hostname="";
public void init ()
{
setBackground(Color.white);
setLayout(new GridBagLayout());
GridBagConstraints GBC=new GridBagConstraints();
LblPrompt=new Label("can not connect to host");
LblPrompt.setAlignment(Label.LEFT);
BtnConn= new Button ("connect");
BtnClose=new Button ("disconnect");
BtnClose.enable(false);
TxtUID= new TextField("",15);
TxtPWD= new TextField("",15);
TxtPWD.setEchoCharacter('*');
TxtHost = new TextField("",20);
Label LblUID= new Label("User ID:");
Label LblPWD= new Label("PWS");
Label LblHost =new Label("Host");
lsArea= new TextArea(30,80);
lsArea.setEditable(false);
GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill=GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(LblPrompt,GBC);
add(LblPrompt);
GBC.gridwidth=1;
( (GridBagLayout)getLayout()).setConstraints(LblHost,GBC) ;
add(LblHost);
GBC.gridwidth=GridBagConstraints.REMAINDER;
((GridBagLayout)getLayout()).setConstraints(TxtHost,GBC);
add(TxtHost);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblUID,GBC);
add(LblUID);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtUID,GBC);
add(TxtUID);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblPWD,GBC);
add(LblPWD);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtPWD,GBC);
add(TxtPWD);
GBC.gridwidth=1;
GBC.weightx=2;
((GridBagLayout)getLayout()).setConstraints(BtnConn,GBC);
add(BtnConn);
GBC.gridwidth=GridBagConstraints.REMAINDER;
((GridBagLayout)getLayout()).setConstraints(BtnClose,GBC);
add(BtnClose);
GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill=GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(lsArea,GBC);
add(lsArea);
}
public boolean connect(String hostname ,String UID,String pwd)
{
this.hostname=hostname;
LblPrompt.setText("connecting ,please waiting ");
try
{
aftp=new FtpClient(hostname);
aftp.login(UID,pwd);
aftp.binary();
showFileContents();
}
catch (FtpLoginException e)
{
a="no private to "+hostname+"connecting";
LblPrompt.setText(a);
return false;
}
catch (IOException e)
{
a="connecting"+hostname+"failed";
LblPrompt.setText(a);
return false;
}
catch (SecurityException e)
{
a="no private to "+hostname+"connecting";
LblPrompt.setText(a);
return false;
}
LblPrompt.setText("connecting"+hostname+"sucess");
return true;
}
public void paint(Graphics g)
{
}
public boolean action(Event evt,Object obj)
{
if (evt.target==BtnConn)
{
LblPrompt.setText("connecting ,please waiting ");
if (connect(TxtHost.getText(),TxtUID.getText(),TxtPWD.getText()))
{
BtnConn.setEnabled(false);
BtnClose.setEnabled(true);
}
return true;
}
return super.action(evt,obj); //super 指代什么??
}
public boolean sendFile(String filepathname)
{
boolean result=true;
if (aftp!=null)
{
LblPrompt.setText("please be patient,now is pasting");
String contentperline;
try
{
a="paste sucess";
String fg= new String ("\");
int index= filepathname.lastIndexOf(fg);
String filename=filepathname.substring(index+1);
File localFile;
localFile =new File (filepathname);
RandomAccessFile sendFile =new RandomAccessFile(filepathname,"r");
//
sendFile.seek(0);
outs=aftp.put(filename);
outputs =new DataOutputStream(outs);
while (sendFile.getFilePointer()=0)
{
buf.append((char)ch);
}
lsArea.appendText(buf.toString());
ins.close();
}
catch (IOException e)
{
}
}
public static void main(String args[])
{
Frame f=new Frame("FTP Clinet");
f.addWindowListener(new WindowAdapter()
{
public void windowCloseing(WindowEvent e)
{
System.exit(0);
}
});
FtpApplet ftp= new FtpApplet();
ftp.init();
ftp.start();
f.add(ftp);
f.pack();
f.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
//package jdeveloper.ftp;
import sun.net.ftp.*;
import sun.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
public class FtpApplet extends Applet
{
FtpClient aftp;
DataOutputStream outputs;
TelnetInputStream ins;
TelnetOutputStream outs;
TextArea lsArea;
Label LblPrompt;
Button BtnConn;
Button BtnClose;
TextField TxtUID;
TextField TxtPWD;
TextField TxtHost;
int ch;
public String a="cannot connect to Host";
String hostname="";
public void init ()
{
setBackground(Color.white);
setLayout(new GridBagLayout());
GridBagConstraints GBC=new GridBagConstraints();
LblPrompt=new Label("can not connect to host");
LblPrompt.setAlignment(Label.LEFT);
BtnConn= new Button ("connect");
BtnClose=new Button ("disconnect");
BtnClose.enable(false);
TxtUID= new TextField("",15);
TxtPWD= new TextField("",15);
TxtPWD.setEchoCharacter('*');
TxtHost = new TextField("",20);
Label LblUID= new Label("User ID:");
Label LblPWD= new Label("PWS");
Label LblHost =new Label("Host");
lsArea= new TextArea(30,80);
lsArea.setEditable(false);
GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill=GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(LblPrompt,GBC);
add(LblPrompt);
GBC.gridwidth=1;
( (GridBagLayout)getLayout()).setConstraints(LblHost,GBC) ;
add(LblHost);
GBC.gridwidth=GridBagConstraints.REMAINDER;
((GridBagLayout)getLayout()).setConstraints(TxtHost,GBC);
add(TxtHost);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblUID,GBC);
add(LblUID);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtUID,GBC);
add(TxtUID);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblPWD,GBC);
add(LblPWD);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtPWD,GBC);
add(TxtPWD);
GBC.gridwidth=1;
GBC.weightx=2;
((GridBagLayout)getLayout()).setConstraints(BtnConn,GBC);
add(BtnConn);
GBC.gridwidth=GridBagConstraints.REMAINDER;
((GridBagLayout)getLayout()).setConstraints(BtnClose,GBC);
add(BtnClose);
GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill=GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(lsArea,GBC);
add(lsArea);
}
public boolean connect(String hostname ,String UID,String pwd)
{
this.hostname=hostname;
LblPrompt.setText("connecting ,please waiting ");
try
{
aftp=new FtpClient(hostname);
aftp.login(UID,pwd);
aftp.binary();
showFileContents();
}
catch (FtpLoginException e)
{
a="no private to "+hostname+"connecting";
LblPrompt.setText(a);
return false;
}
catch (IOException e)
{
a="connecting"+hostname+"failed";
LblPrompt.setText(a);
return false;
}
catch (SecurityException e)
{
a="no private to "+hostname+"connecting";
LblPrompt.setText(a);
return false;
}
LblPrompt.setText("connecting"+hostname+"sucess");
return true;
}
public void paint(Graphics g)
{
}
public boolean action(Event evt,Object obj)
{
if (evt.target==BtnConn)
{
LblPrompt.setText("connecting ,please waiting ");
if (connect(TxtHost.getText(),TxtUID.getText(),TxtPWD.getText()))
{
BtnConn.setEnabled(false);
BtnClose.setEnabled(true);
}
return true;
}
return super.action(evt,obj); //super 指代什么??
}
public boolean sendFile(String filepathname)
{
boolean result=true;
if (aftp!=null)
{
LblPrompt.setText("please be patient,now is pasting");
String contentperline;
try
{
a="paste sucess";
String fg= new String ("\");
int index= filepathname.lastIndexOf(fg);
String filename=filepathname.substring(index+1);
File localFile;
localFile =new File (filepathname);
RandomAccessFile sendFile =new RandomAccessFile(filepathname,"r");
//
sendFile.seek(0);
outs=aftp.put(filename);
outputs =new DataOutputStream(outs);
while (sendFile.getFilePointer()=0)
{
buf.append((char)ch);
}
lsArea.appendText(buf.toString());
ins.close();
}
catch (IOException e)
{
}
}
public static void main(String args[])
{
Frame f=new Frame("FTP Clinet");
f.addWindowListener(new WindowAdapter()
{
public void windowCloseing(WindowEvent e)
{
System.exit(0);
}
});
FtpApplet ftp= new FtpApplet();
ftp.init();
ftp.start();
f.add(ftp);
f.pack();
f.setVisible(true);
}
}
|
super代表基类
return super.action(evt,obj);
用的是递归,也就是自己调用自己
return super.action(evt,obj);
用的是递归,也就是自己调用自己
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。