?? loginframe.java
字號:
/*
* LoginFrame.java
*
* Created on 2008年12月1日, 上午8:53
*/
package com.topking.ftp.ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import javax.swing.UnsupportedLookAndFeelException;
import sun.net.ftp.FtpClient;
import com.topking.ftp.validate.InputValidate;
/**
*
* @author lzkj
*/
public class LoginFrame extends javax.swing.JFrame {
/** Creates new form LoginFrame */
// Variables declaration - do not modify
private javax.swing.JLabel L_icon;
private javax.swing.JLabel L_txt;
private javax.swing.JTextField T_host;
private javax.swing.JPasswordField T_passWord;
private javax.swing.JTextField T_userName;
private javax.swing.JButton bt_login;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private FtpClient ftp;
// End of variables declaration
public LoginFrame() {
this.setTitle("FTP登錄 @Author:jacky");
this.setLocation(200, 300);
this.setResizable(false);
this.setIconImage(this.getToolkit().createImage(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/ftp.gif")));
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel("FTP主機IP",new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/icon_home.gif")),SwingConstants.LEFT);
T_host = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel("用 戶 名",new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/icon_padlock.gif")),SwingConstants.LEFT);
T_userName = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel("密 碼",new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/icon_key.gif")),SwingConstants.LEFT);
T_passWord = new javax.swing.JPasswordField();
bt_login = new javax.swing.JButton();
L_icon = new javax.swing.JLabel();
L_txt = new javax.swing.JLabel();
T_host.setText("192.168.1.100");
T_userName.setText("root");
T_passWord.setText("root");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
bt_login.setText("登錄");
bt_login.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(!InputValidate.inputIsNull(LoginFrame.this, "FTP主機IP", T_host.getText())&&
!InputValidate.inputIsNull(LoginFrame.this, "用戶名", T_userName.getText())&&
!InputValidate.inputIsNull(LoginFrame.this, "密碼", new String(T_passWord.getPassword()).trim())){
String host = T_host.getText().trim();
String name = T_userName.getText().trim();
String pass = new String(T_passWord.getPassword()).trim();
new Thread(new refreshUI()).start();
new Thread(new loginThread(host,name,pass)).start();
}
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(L_icon, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(L_txt, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(T_passWord)
.addComponent(T_userName)
.addComponent(T_host, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(bt_login)))
.addContainerGap(12, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(T_host, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(T_userName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(T_passWord, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(bt_login)
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(L_icon, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)
.addComponent(L_txt, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}// </editor-fold>
public class loginThread implements Runnable{
private String host;
private String name;
private String pass;
public loginThread(String host,String name,String pass){
this.host = host;
this.name = name;
this.pass = pass;
}
@Override
public void run() {
ftp = login();
if(ftp!=null){
new MainFrame(ftp,host,name,pass).setVisible(true);
destoryWindow();
}
}
public FtpClient login(){
FtpClient ftpClient = null;
// System.out.println("開始登錄服務器......");
try {
ftpClient = new FtpClient();
ftpClient.openServer(host);
ftpClient.login(name, pass);
L_txt.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/add.gif")));
L_txt.setText("恭喜你 登錄成功");
} catch (IOException e) {
// TODO Auto-generated catch block
L_txt.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/delete.gif")));
L_txt.setText("登錄失敗(IP/用戶名/密碼錯誤)");
e.printStackTrace();
}
return ftpClient;
}
}
public void destoryWindow(){
this.dispose();
}
public class refreshUI implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
L_txt.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource("com/topking/ftp/ui/images/spinner.gif")));
L_txt.setText("正在登錄 請稍后……");
}
}
// E://jacky/www.guaguali.com_30/WebRoot
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
javax.swing.UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
com.birosoft.liquid.LiquidLookAndFeel.setLiquidDecorations(true);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoginFrame().setVisible(true);
}
});
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -