|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
什么时候上述的三种开发工具能和三为一,什么时候java的竞争力才更强,才有机会拉拢更多的程序员投入到对java的开发上,因为到时的开发工具将会比.net的更简单。还有一点也很关键,什么时候java推出的jsf能成为真正意义上的标准。源代码importsun.net.ftp.*;
importsun.net.*;
importjava.awt.*;
importjava.awt.event.*;
importjava.applet.*;
importjava.io.*;
publicclassFtpAppletextendsApplet
{
FtpClientaftp;
DataOutputStreamoutputs;
TelnetInputStreamins;
TelnetOutputStreamouts;
TextArealsArea;
LabelLblPrompt;
ButtonBtnConn;
ButtonBtnClose;
TextFieldTxtUID;
TextFieldTxtPWD;
TextFieldTxtHost;
intch;
publicStringa="没有毗连主机";
Stringhostname="";
publicvoidinit(){
setBackground(Color.white);
setLayout(newGridBagLayout());
GridBagConstraintsGBC=newGridBagConstraints();
LblPrompt=newLabel("没有毗连主机");
LblPrompt.setAlignment(Label.LEFT);
BtnConn=newButton("毗连");
BtnClose=newButton("断开");
BtnClose.enable(false);
TxtUID=newTextField("",15);
TxtPWD=newTextField("",15);
TxtPWD.setEchoCharacter(’*’);
TxtHost=newTextField("",20);
LabelLblUID=newLabel("UserID:");
LabelLblPWD=newLabel("PWD:");
LabelLblHost=newLabel("Host:");
lsArea=newTextArea(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);
}
publicbooleanconnect(Stringhostname,Stringuid,Stringpwd)
{
this.hostname=hostname;
LblPrompt.setText("正在毗连,请守候.....");
try{
aftp=newFtpClient(hostname);
aftp.login(uid,pwd);
aftp.binary();
showFileContents();
}
catch(FtpLoginExceptione){
a="无权限与主机:"+hostname+"毗连!";
LblPrompt.setText(a);
returnfalse;
}
catch(IOExceptione){
a="毗连主机:"+hostname+"失利!";
LblPrompt.setText(a);
returnfalse;
}
catch(SecurityExceptione)
{
a="无权限与主机:"+hostname+"毗连!";
LblPrompt.setText(a);
returnfalse;
}
LblPrompt.setText("毗连主机:"+hostname+"乐成!");
returntrue;
}
publicvoidstop()
{
try
{
aftp.closeServer();
}
catch(IOExceptione)
{
}
}
publicvoidpaint(Graphicsg){
}
publicbooleanaction(Eventevt,Objectobj)
{
if(evt.target==BtnConn)
{
LblPrompt.setText("正在毗连,请守候.....");
if(connect(TxtHost.getText(),TxtUID.getText(),TxtPWD.getText()))
{
BtnConn.setEnabled(false);
BtnClose.setEnabled(true);
}
returntrue;
}
if(evt.target==BtnClose)
{
stop();
BtnConn.enable(true);
BtnClose.enable(false);
LblPrompt.setText("与主机"+hostname+"毗连已断开!");
returntrue;
}
returnsuper.action(evt,obj);
}
publicbooleansendFile(Stringfilepathname){
booleanresult=true;
if(aftp!=null)
{
LblPrompt.setText("正在粘贴文件,请耐烦守候....");
Stringcontentperline;
try{
a="粘贴乐成!";
Stringfg=newString("");
intindex=filepathname.lastIndexOf(fg);
Stringfilename=filepathname.substring(index+1);
FilelocalFile;
localFile=newFile(filepathname);
RandomAccessFilesendFile=newRandomAccessFile(filepathname,"r");
//
sendFile.seek(0);
outs=aftp.put(filename);
outputs=newDataOutputStream(outs);
while(sendFile.getFilePointer()<sendFile.length())
{
ch=sendFile.read();
outputs.write(ch);
}
outs.close();
sendFile.close();
}
catch(IOExceptione){
a="粘贴失利!";
result=false;
}
LblPrompt.setText(a);
showFileContents();
}
else{
result=false;
}
returnresult;
}
publicvoidshowFileContents()
{
StringBufferbuf=newStringBuffer();
lsArea.setText("");
try
{
ins=aftp.list();
while((ch=ins.read())>=0){
buf.append((char)ch);
}
lsArea.appendText(buf.toString());
ins.close();
}
catch(IOExceptione)
{
}
}
publicstaticvoidmain(Stringargs[]){
Framef=newFrame("FTPClient");
f.addWindowListener(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
});
FtpAppletftp=newFtpApplet();
ftp.init();
ftp.start();
f.add(ftp);
f.pack();
f.setVisible(true);
}
}
java也能做一些底层语言开发做的事情(难度很高,不是java顶尖高手是做不来的), |
|