📄 frame1.java~51~
字号:
package ftpclient;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import sun.net.ftp.*;
import com.borland.jbcl.layout.*;
import java.beans.*;
import java.io.*;
import sun.net.TelnetInputStream;
/**
* <p>Title: an example</p>
* <p>Description:an no</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: home</p>
* @author liujun
* @version 1.0
*/
public class Frame1 extends JFrame {
private JPanel contentPane;
private TextField textField1 = new TextField();
private XYLayout xYLayout1 = new XYLayout();
private Button button1 = new Button();
private TextField textField2 = new TextField();
private TextField textField3 = new TextField();
private Checkbox checkbox1 = new Checkbox();
private List list1 = new List();
private TextArea textArea1 = new TextArea();
FtpClient ftp=null;
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
textField1.setText("202.112.116.5");
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
button1.setLabel("登录");
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
button1_actionPerformed(e);
}
});
textField2.setText("anonymous");
textField3.setText("a");
checkbox1.setLabel("匿名");
checkbox1.setState(true);
checkbox1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
checkbox1_propertyChange(e);
}
});
list1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
list1_mouseClicked(e);
}
});
contentPane.add(textField1, new XYConstraints(11, 14, 160, -1));
contentPane.add(button1, new XYConstraints(125, 47, 58, 21));
contentPane.add(textField2, new XYConstraints(15, 50, 80, 18));
contentPane.add(textField3, new XYConstraints(14, 79, 80, 19));
contentPane.add(checkbox1, new XYConstraints(124, 79, 58, 20));
contentPane.add(list1, new XYConstraints(196, 12, 190, 98));
contentPane.add(textArea1, new XYConstraints(17, 119, 367, 150));
}
//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 checkbox1_propertyChange(PropertyChangeEvent e) {
if(checkbox1.getState()){
textField1.setText("anonymous");
textField2.setText("a");
}
}
void button1_actionPerformed(ActionEvent e) {
StringBuffer buf=new StringBuffer();
int ch;
list1.removeAll();
try {
if (ftp!=null) ftp.closeServer();
}
catch (IOException ex) {
ex.printStackTrace();
}
try {
ftp= new FtpClient(textField1.getText());
ftp.login(textField2.getText(),textField3.getText());
ftp.ascii();
TelnetInputStream t=ftp.list();
t.setStickyCRLF(true);
while((ch=t.read())>=0){
if(ch=='\n')
{
list1.add(buf.toString());
buf.setLength(0);
}else{
buf.append((char)ch);
}
}
t.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
void list1_mouseClicked(MouseEvent e) {
StringBuffer buf=new StringBuffer();
int ch;
String dir=list1.getSelectedItem();
int begin=0;
int k=dir.length()-1;
while(dir.charAt(k)==' ') k--;
for(int i=k;i>1;i--){
if(dir.charAt(k)==' ') {
begin=k;
break;
}
}
textArea1.append("目录: ");
textArea1.append(dir.substring(begin));
textArea1.append("\n");
try {
ftp.cd(dir.substring(begin));
TelnetInputStream t=ftp.list();
while((ch=t.read())>=0)
buf.append((char)ch);
t.close();
textArea1.append(buf.toString());
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -