📄 fclient.java
字号:
package ftpclient;
import cmd.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.io.Serializable;
import java.io.File;
import javax.swing.JSplitPane;
import java.util.Vector;
import cmd.*;
public class FClient
extends JFrame {
private JPanel barPane=new JPanel();
private JPanel remotePane = new JPanel();
private JSplitPane mainPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
private JSplitPane rightPane=new JSplitPane(JSplitPane.VERTICAL_SPLIT);
private JTextArea inforPane = new JTextArea();
private JTextField hostField;
private JTextField portField;
private JTextField userField;
private JPasswordField pwdField;
private JLabel hostLabel;
private JLabel portLabel;
private JLabel userLabel;
private JLabel pwdLabel;
private JButton connect;
private JButton disconnect;
private Vector clist, alist;
private RemoteFileTree rft;
private RemoteFileList rfl;
public FClient() {
clist = new Vector();
alist = new Vector();
init();
new MessageManager(inforPane);
}
public void init() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(barPane,BorderLayout.NORTH);
contentPane.add(mainPane,BorderLayout.CENTER);
this.setSize(new Dimension(800,600));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("cuteFTP Client");
init1();
init2();
disconnect.setEnabled(false);
this.setVisible(true);
}
private void init1() {
hostField = new JTextField("192.168.0.203",15);
portField = new JTextField("21",5);
userField = new JTextField("mse06",10);
pwdField = new JPasswordField("mse06",10);
hostLabel = new JLabel("host");
portLabel = new JLabel("port");
userLabel = new JLabel("user");
pwdLabel = new JLabel("pwd");
ImageIcon con = new ImageIcon("D:/mypro/Ftp/src/image/run.gif");
connect = new JButton(con);
connect.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent avt){
String host = hostField.getText().trim();
String user = userField.getText().trim();
String pass = new String(pwdField.getPassword()).trim();
String port = portField.getText().trim();
CommandArgument[] ca= new CommandArgument[4];
for(int i=0;i<ca.length;i++){
ca[i] = new CommandArgument();
}
ca[0].setArgument(host,port );
if(user.equals("")){
ca[1].setArgument("anonymous","");
}else{
ca[1].setArgument(user, "");
}
if(pass.equals("")){
ca[2].setArgument("anonymous", "");
}else{
ca[2].setArgument(pass, "");
}
ca[3].setArgument("","");
for(int i=0;i<ca.length;i++)
alist.addElement(ca[i]);
clist.addElement("Connect");
clist.addElement("User");
clist.addElement("Pass");
clist.addElement("List");
TransactionCommand tc = new TransactionCommand(clist, alist);
CommandManager cm = new CommandManager(tc);
cm.runCommands();
Vector filesname = CommandReceiver.filesname;
//rft = new RemoteFileTree();
//rft.createNodes(rft.root,filesname);
//JScrollPane js3 = new JScrollPane(rft);
//占满整个区域
rfl=new RemoteFileList(filesname);
JScrollPane js3 = new JScrollPane(rfl);
remotePane.setLayout(
new BoxLayout(remotePane,BoxLayout.Y_AXIS));
remotePane.add(js3);
//重绘
remotePane.setVisible(false);
remotePane.setVisible(true);
disconnect.setEnabled(true);
}
});
disconnect = new JButton("disconnect");
disconnect.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
disconnect.setEnabled(false);
connect.setEnabled(true);
clist.removeAllElements();
alist.removeAllElements();
clist.add("Quit");
alist.add(new CommandArgument());
TransactionCommand tc = new TransactionCommand(clist,alist);
CommandManager cm = new CommandManager(tc);
cm.runCommands();
remotePane.removeAll();
rfl.removeAll();
CommandReceiver.filesname.removeAllElements();
remotePane.setVisible(false);
remotePane.setVisible(true);
}
});
GridBagConstraints layout=new GridBagConstraints();
add(hostLabel,layout,0,0,1,1);
add(hostField,layout,0,1,2,1);
add(portLabel,layout,0,3,1,1);
add(portField,layout,0,4,1,1);
add(userLabel,layout,0,5,1,1);
add(userField,layout,0,6,1,1);
add(pwdLabel,layout,0,7,1,1);
add(pwdField,layout,0,8,1,1);
add(connect,layout,0,9,1,1);
add(disconnect,layout,0,10,1,1);
}
private void init2(){
mainPane.setResizeWeight(0.1);
rightPane.setResizeWeight(0.7);
mainPane.setRightComponent(rightPane);
LocalFileTree ajb = new LocalFileTree();
JScrollPane js1 = new JScrollPane(ajb);
mainPane.setLeftComponent(js1);
JScrollPane js2 = new JScrollPane(inforPane);
rightPane.setTopComponent(remotePane);
rightPane.setBottomComponent(js2);
inforPane.setLineWrap(true);
}
public void add(Component c,GridBagConstraints constrains,
int x,int y,int w,int h){
constrains.gridx=x;
constrains.gridy=y;
constrains.gridwidth=w;
constrains.gridheight=h;
barPane.add(c,constrains);
}
public static void main(String args[]){
FClient myftp=new FClient();
myftp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -