package ignisftpv20; import javax.swing.JFileChooser; import java.io.*; public class FTPClientInterface extends javax.swing.JFrame implements Runnable { JFileChooser fileChooser = new JFileChooser(); File fileUpload; FTPClient theFTPClient; public FTPClientInterface(FTPClient c) { initComponents(); theFTPClient = c; } @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { btnBrowse = new javax.swing.JButton(); btnSend = new javax.swing.JButton(); btnConnect = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("FTP Client"); btnBrowse.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N btnBrowse.setText("Browse"); btnBrowse.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBrowseActionPerformed(evt); } }); btnSend.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N btnSend.setText("Send File"); btnSend.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSendActionPerformed(evt); } }); btnConnect.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N btnConnect.setText("Connect"); btnConnect.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnConnectActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(66, 66, 66) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnSend) .addComponent(btnBrowse) .addComponent(btnConnect)) .addContainerGap(80, Short.MAX_VALUE)) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnBrowse, btnConnect, btnSend}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(56, 56, 56) .addComponent(btnConnect) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnBrowse) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnSend, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(63, Short.MAX_VALUE)) ); layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnBrowse, btnConnect, btnSend}); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-237)/2, (screenSize.height-268)/2, 237, 268); }// //GEN-END:initComponents //browse private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed int flag = fileChooser.showOpenDialog(FTPClientInterface.this); if (flag == JFileChooser.APPROVE_OPTION) { fileUpload = fileChooser.getSelectedFile(); //theFTPClient.sendBytes(fileUpload); } }//GEN-LAST:event_btnBrowseActionPerformed //connect private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed new Thread( this ).start(); }//GEN-LAST:event_btnConnectActionPerformed //send file private void btnSendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendActionPerformed theFTPClient.sendBytes(fileUpload); }//GEN-LAST:event_btnSendActionPerformed public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { FTPClient c = new FTPClient(); new FTPClientInterface(c).setVisible(true); } }); } public void run(){ try{ new FTPClient(5555); }//end try catch(Exception e){e.printStackTrace();} } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnBrowse; private javax.swing.JButton btnConnect; private javax.swing.JButton btnSend; // End of variables declaration//GEN-END:variables }