下載
建立界面
private JFileChooser filePicker;
filePicker = new JFileChooser(); filePicker.setBounds(10, 180, 200,200); contentPane.add(filePicker);
UploadTask task = new UploadTask(ip.getText(), Integer.parseInt(port.getText()), username.getText(), password.getText(), "", filePicker.getSelectedFile()); task.addPropertyChangeListener(this); task.execute();
import java.awt.EventQueue; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.border.EmptyBorder; public class FtpClient extends JFrame implements PropertyChangeListener{ private JPanel contentPane; private JTextField ip; private JTextField port; private JTextField username; private JTextField password; private JFileChooser filePicker; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { FtpClient frame = new FtpClient(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public FtpClient() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 531, 585); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); ip = new JTextField(); ip.setBounds(86, 10, 419, 33); contentPane.add(ip); ip.setColumns(10); port = new JTextField(); port.setColumns(10); port.setBounds(86, 55, 419, 33); contentPane.add(port); username = new JTextField(); username.setColumns(10); username.setBounds(86, 96, 419, 33); contentPane.add(username); password = new JTextField(); password.setColumns(10); password.setBounds(86, 139, 419, 33); contentPane.add(password); JLabel lblIp = new JLabel("IP\u4F4D\u5740"); lblIp.setFont(new Font("微軟正黑體", Font.PLAIN, 18)); lblIp.setBounds(14, 11, 73, 35); contentPane.add(lblIp); JLabel lblIp_1 = new JLabel("\u5E33\u865F"); lblIp_1.setFont(new Font("微軟正黑體", Font.PLAIN, 18)); lblIp_1.setBounds(13, 97, 73, 35); contentPane.add(lblIp_1); JLabel lblIp_2 = new JLabel("\u5BC6\u78BC"); lblIp_2.setFont(new Font("微軟正黑體", Font.PLAIN, 18)); lblIp_2.setBounds(13, 140, 73, 35); contentPane.add(lblIp_2); JLabel lblIp_3 = new JLabel("\u9023\u63A5\u57E0"); lblIp_3.setFont(new Font("微軟正黑體", Font.PLAIN, 18)); lblIp_3.setBounds(11, 57, 73, 35); contentPane.add(lblIp_3); filePicker = new JFileChooser(); filePicker.setBounds(10, 180, 495,314); contentPane.add(filePicker); JButton btnNewButton = new JButton("\u4E0A\u50B3\u6A94\u6848"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { UploadTask task = new UploadTask(ip.getText(), Integer.parseInt(port.getText()), username.getText(), password.getText(), "", filePicker.getSelectedFile()); task.addPropertyChangeListener(this); task.execute(); } }); btnNewButton.setFont(new Font("微軟正黑體", Font.PLAIN, 18)); btnNewButton.setBounds(9, 504, 492, 32); contentPane.add(btnNewButton); } @Override public void propertyChange(PropertyChangeEvent evt) { // TODO Auto-generated method stub } }
沒有留言:
張貼留言