Source Code : Exercises the various protocols available in the Commons Net Package

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Exercises the various protocols available in the Commons Net Package

/*
 * ProtocolRunner.java
 *
 * Created on 22 December 2003, 12:57
 */
// Import Java Packages
import java.awt.Point;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.Component;
import java.io.IOException;

import javax.swing.JLabel;
import javax.swing.JDialog;
import javax.swing.UIManager;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import java.net.SocketException;

import java.io.File;
import java.util.Date;
import java.util.Calendar;
import javax.swing.JDialog;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.GregorianCalendar;

// Import NET Packages
import org.apache.commons.net.*;
import org.apache.commons.net.io.*;
import org.apache.commons.net.ftp.*;
import org.apache.commons.net.nntp.*;
import org.apache.commons.net.pop3.*;
import org.apache.commons.net.smtp.*;
import org.apache.commons.net.tftp.*;

/**
 * ProtocolRunner class exercises the various protocols available in the
 * Commons Net Package
 * @author  Vikram Goyal
 */
public class ProtocolRunner extends javax.swing.JFrame {
    
    /** Creates new form ProtocolRunner */
    public ProtocolRunner() { 
        // set the native look and feel
        try{
            UIManager.setLookAndFeel(
                UIManager.getSystemLookAndFeelClassName());
        }catch(Exception e) {}
        
        initComponents();
        // size it so that it appears full screen
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        this.setSize(screen.width, screen.height);
        this.pack();
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
    }
    
    /** 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.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        ftpPanel = new javax.swing.JPanel();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton8 = new javax.swing.JRadioButton();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        nntpPanel = new javax.swing.JPanel();
        jRadioButton10 = new javax.swing.JRadioButton();
        jRadioButton15 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton11 = new javax.swing.JRadioButton();
        jRadioButton12 = new javax.swing.JRadioButton();
        jRadioButton13 = new javax.swing.JRadioButton();
        jRadioButton14 = new javax.swing.JRadioButton();
        smtpPanel = new javax.swing.JPanel();
        jRadioButton17 = new javax.swing.JRadioButton();
        jRadioButton18 = new javax.swing.JRadioButton();
        jRadioButton16 = new javax.swing.JRadioButton();
        pop3Panel = new javax.swing.JPanel();
        jRadioButton19 = new javax.swing.JRadioButton();
        jRadioButton20 = new javax.swing.JRadioButton();
        jRadioButton21 = new javax.swing.JRadioButton();
        jRadioButton22 = new javax.swing.JRadioButton();
        jRadioButton23 = new javax.swing.JRadioButton();
        jRadioButton24 = new javax.swing.JRadioButton();
        jRadioButton9 = new javax.swing.JRadioButton();
        ftpButtonGroup = new javax.swing.ButtonGroup();
        nntpButtonGroup = new javax.swing.ButtonGroup();
        smtpButtonGroup = new javax.swing.ButtonGroup();
        pop3ButtonGroup = new javax.swing.ButtonGroup();
        tftpPanel = new javax.swing.JPanel();
        jRadioButton25 = new javax.swing.JRadioButton();
        jRadioButton26 = new javax.swing.JRadioButton();
        tftpPanelButtonGroup = new javax.swing.ButtonGroup();
        loginDialog = new javax.swing.JDialog();
        jLabel9 = new javax.swing.JLabel();
        jPanel13 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        loginUsername = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        loginPassword = new javax.swing.JPasswordField();
        jPanel14 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        singleValueDialog = new javax.swing.JDialog();
        jLabel12 = new javax.swing.JLabel();
        jPanel15 = new javax.swing.JPanel();
        singleValueLabel = new javax.swing.JLabel();
        singleValueField = new javax.swing.JTextField();
        jPanel16 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        multipleValueDialog = new javax.swing.JDialog();
        jLabel13 = new javax.swing.JLabel();
        jPanel17 = new javax.swing.JPanel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jPanel18 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        messageArea = new javax.swing.JTextArea();
        jPanel19 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        fromField = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        subjectField = new javax.swing.JTextField();
        variableLabel = new javax.swing.JLabel();
        variableField = new javax.swing.JTextField();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tcpServerResponse = new javax.swing.JTextArea();
        jPanel7 = new javax.swing.JPanel();
        presetPanel = new javax.swing.JPanel();
        defaultPanel = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        commandBox = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        tcpSelectionBox = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        serverNameField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        portNumberField = new javax.swing.JTextField();
        tcpConnectButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        udpSelectionBox = new javax.swing.JComboBox();
        jPanel12 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        udpRemoteServerField = new javax.swing.JTextField();
        jPanel11 = new javax.swing.JPanel();
        udpCommandPanel = new javax.swing.JPanel();
        udpStartButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        udpServerResponse = new javax.swing.JTextArea();

        ftpPanel.setLayout(new java.awt.GridLayout(3, 3));

        jRadioButton4.setText("Login");
        ftpButtonGroup.add(jRadioButton4);
        jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton4ActionPerformed(evt);
            }
        });

        ftpPanel.add(jRadioButton4);

        jRadioButton8.setText("Logout");
        ftpButtonGroup.add(jRadioButton8);
        jRadioButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton8ActionPerformed(evt);
            }
        });

        ftpPanel.add(jRadioButton8);

        jRadioButton1.setText("Change Working Directory");
        ftpButtonGroup.add(jRadioButton1);
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        ftpPanel.add(jRadioButton1);

        jRadioButton3.setText("List Files");
        ftpButtonGroup.add(jRadioButton3);
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        ftpPanel.add(jRadioButton3);

        jRadioButton5.setText("Make Directory");
        ftpButtonGroup.add(jRadioButton5);
        jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton5ActionPerformed(evt);
            }
        });

        ftpPanel.add(jRadioButton5);

        jRadioButton6.setText("Upload File");
        ftpButtonGroup.add(jRadioButton6);
        jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton6ActionPerformed(evt);
            }
        });

        ftpPanel.add(jRadioButton6);

        jRadioButton7.setText("Download File");
        ftpButtonGroup.add(jRadioButton7);
        jRadioButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton7ActionPerformed(evt);
            }
        });

        ftpPanel.add(jRadioButton7);

        nntpPanel.setLayout(new java.awt.GridLayout(3, 3));

        jRadioButton10.setText("Login");
        nntpButtonGroup.add(jRadioButton10);
        jRadioButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton10ActionPerformed(evt);
            }
        });

        nntpPanel.add(jRadioButton10);

        jRadioButton15.setText("Logout");
        nntpButtonGroup.add(jRadioButton15);
        jRadioButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton15ActionPerformed(evt);
            }
        });

        nntpPanel.add(jRadioButton15);

        jRadioButton2.setText("List All NewsGroups");
        nntpButtonGroup.add(jRadioButton2);
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        nntpPanel.add(jRadioButton2);

        jRadioButton11.setText("List New NewsGroups");
        nntpButtonGroup.add(jRadioButton11);
        jRadioButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton11ActionPerformed(evt);
            }
        });

        nntpPanel.add(jRadioButton11);

        jRadioButton12.setText("List New News");
        nntpButtonGroup.add(jRadioButton12);
        jRadioButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton12ActionPerformed(evt);
            }
        });

        nntpPanel.add(jRadioButton12);

        jRadioButton13.setText("Post Article");
        nntpButtonGroup.add(jRadioButton13);
        jRadioButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton13ActionPerformed(evt);
            }
        });

        nntpPanel.add(jRadioButton13);

        jRadioButton14.setText("Get Article");
        nntpButtonGroup.add(jRadioButton14);
        jRadioButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton14ActionPerformed(evt);
            }
        });

        nntpPanel.add(jRadioButton14);

        smtpPanel.setLayout(new java.awt.GridLayout(1, 1));

        jRadioButton17.setText("Login");
        smtpButtonGroup.add(jRadioButton17);
        jRadioButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton17ActionPerformed(evt);
            }
        });

        smtpPanel.add(jRadioButton17);

        jRadioButton18.setText("Logout");
        smtpButtonGroup.add(jRadioButton18);
        jRadioButton18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton18ActionPerformed(evt);
            }
        });

        smtpPanel.add(jRadioButton18);

        jRadioButton16.setText("Send Simple Message");
        smtpButtonGroup.add(jRadioButton16);
        jRadioButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton16ActionPerformed(evt);
            }
        });

        smtpPanel.add(jRadioButton16);

        pop3Panel.setLayout(new java.awt.GridLayout(2, 0));

        jRadioButton19.setText("Login");
        pop3ButtonGroup.add(jRadioButton19);
        jRadioButton19.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton19ActionPerformed(evt);
            }
        });

        pop3Panel.add(jRadioButton19);

        jRadioButton20.setText("Logout");
        pop3ButtonGroup.add(jRadioButton20);
        jRadioButton20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton20ActionPerformed(evt);
            }
        });

        pop3Panel.add(jRadioButton20);

        jRadioButton21.setText("List All Messages");
        pop3ButtonGroup.add(jRadioButton21);
        jRadioButton21.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton21ActionPerformed(evt);
            }
        });

        pop3Panel.add(jRadioButton21);

        jRadioButton22.setText("Status");
        pop3ButtonGroup.add(jRadioButton22);
        jRadioButton22.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton22ActionPerformed(evt);
            }
        });

        pop3Panel.add(jRadioButton22);

        jRadioButton23.setText("Retrieve Message");
        pop3ButtonGroup.add(jRadioButton23);
        jRadioButton23.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton23ActionPerformed(evt);
            }
        });

        pop3Panel.add(jRadioButton23);

        jRadioButton24.setText("Delete Message");
        pop3ButtonGroup.add(jRadioButton24);
        jRadioButton24.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton24ActionPerformed(evt);
            }
        });

        pop3Panel.add(jRadioButton24);

        jRadioButton9.setText("Reset");
        pop3ButtonGroup.add(jRadioButton9);
        jRadioButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton9ActionPerformed(evt);
            }
        });

        pop3Panel.add(jRadioButton9);

        tftpPanel.setLayout(new java.awt.GridLayout(1, 0));

        jRadioButton25.setText("Send A File");
        tftpPanelButtonGroup.add(jRadioButton25);
        jRadioButton25.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton25ActionPerformed(evt);
            }
        });

        tftpPanel.add(jRadioButton25);

        jRadioButton26.setText("Receive A File");
        tftpPanelButtonGroup.add(jRadioButton26);
        jRadioButton26.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton26ActionPerformed(evt);
            }
        });

        tftpPanel.add(jRadioButton26);

        loginDialog.getContentPane().setLayout(new java.awt.BorderLayout(0, 5));

        loginDialog.setTitle("Input Required");
        loginDialog.setModal(true);
        loginDialog.setResizable(false);
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setText("Please Enter Login Details");
        loginDialog.getContentPane().add(jLabel9, java.awt.BorderLayout.NORTH);

        jPanel13.setLayout(new java.awt.GridLayout(2, 2, 5, 3));

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("Username:");
        jPanel13.add(jLabel10);

        loginUsername.setColumns(15);
        jPanel13.add(loginUsername);

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText("Password:");
        jPanel13.add(jLabel11);

        loginPassword.setColumns(15);
        jPanel13.add(loginPassword);

        loginDialog.getContentPane().add(jPanel13, java.awt.BorderLayout.CENTER);

        jPanel14.setLayout(new java.awt.GridLayout(1, 0));

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel14.add(jButton1);

        jButton2.setText("Cancel");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel14.add(jButton2);

        loginDialog.getContentPane().add(jPanel14, java.awt.BorderLayout.SOUTH);

        singleValueDialog.setTitle("Input Required");
        singleValueDialog.setModal(true);
        singleValueDialog.setResizable(false);
        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel12.setText("Please enter a value");
        singleValueDialog.getContentPane().add(jLabel12, java.awt.BorderLayout.NORTH);

        jPanel15.setLayout(new java.awt.GridLayout(1, 0, 3, 0));

        singleValueLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jPanel15.add(singleValueLabel);

        singleValueField.setColumns(15);
        jPanel15.add(singleValueField);

        singleValueDialog.getContentPane().add(jPanel15, java.awt.BorderLayout.CENTER);

        jPanel16.setLayout(new java.awt.GridLayout(1, 0, 5, 0));

        jButton3.setText("OK");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jPanel16.add(jButton3);

        jButton4.setText("Cancel");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jPanel16.add(jButton4);

        singleValueDialog.getContentPane().add(jPanel16, java.awt.BorderLayout.SOUTH);

        multipleValueDialog.setTitle("Input Required");
        multipleValueDialog.setModal(true);
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel13.setText("Please enter the following values");
        multipleValueDialog.getContentPane().add(jLabel13, java.awt.BorderLayout.NORTH);

        jPanel17.setLayout(new java.awt.GridLayout(1, 0, 5, 0));

        jButton5.setText("OK");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jPanel17.add(jButton5);

        jButton6.setText("Cancel");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jPanel17.add(jButton6);

        multipleValueDialog.getContentPane().add(jPanel17, java.awt.BorderLayout.SOUTH);

        jPanel18.setLayout(new java.awt.BorderLayout());

        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel16.setText("Enter Message:");
        jPanel18.add(jLabel16, java.awt.BorderLayout.WEST);

        messageArea.setColumns(20);
        messageArea.setRows(15);
        jScrollPane3.setViewportView(messageArea);

        jPanel18.add(jScrollPane3, java.awt.BorderLayout.CENTER);

        jPanel19.setLayout(new java.awt.GridLayout(3, 2, 3, 3));

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel14.setText("From:");
        jPanel19.add(jLabel14);

        fromField.setColumns(15);
        jPanel19.add(fromField);

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel15.setText("Subject:");
        jPanel19.add(jLabel15);

        subjectField.setColumns(15);
        jPanel19.add(subjectField);

        variableLabel.setText("Newsgroup:");
        jPanel19.add(variableLabel);

        variableField.setColumns(15);
        jPanel19.add(variableField);

        jPanel18.add(jPanel19, java.awt.BorderLayout.NORTH);

        multipleValueDialog.getContentPane().add(jPanel18, java.awt.BorderLayout.CENTER);

        setTitle("Protocol Runner");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel4.setLayout(new java.awt.BorderLayout());

        jScrollPane1.setBorder(new javax.swing.border.TitledBorder("Server Output"));
        tcpServerResponse.setEditable(false);
        tcpServerResponse.setFont(new java.awt.Font("Monospaced", 0, 12));
        jScrollPane1.setViewportView(tcpServerResponse);

        jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel7.setLayout(new java.awt.GridLayout(1, 2, 5, 0));

        presetPanel.setLayout(new java.awt.BorderLayout());

        presetPanel.setBorder(new javax.swing.border.TitledBorder("Preset Commands"));
        jLabel5.setFont(new java.awt.Font("Dialog", 3, 12));
        jLabel5.setText("No Preset Commands. Simply Connect");
        defaultPanel.add(jLabel5);

        presetPanel.add(defaultPanel, java.awt.BorderLayout.CENTER);

        jPanel7.add(presetPanel);

        jPanel9.setBorder(new javax.swing.border.TitledBorder("Freeflow Commands"));
        jLabel4.setText("Type Command Here:");
        jPanel9.add(jLabel4);

        commandBox.setColumns(15);
        commandBox.setEnabled(false);
        commandBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                commandBoxActionPerformed(evt);
            }
        });

        jPanel9.add(commandBox);

        jPanel7.add(jPanel9);

        jPanel4.add(jPanel7, java.awt.BorderLayout.NORTH);

        jPanel1.add(jPanel4, java.awt.BorderLayout.CENTER);

        jPanel5.setLayout(new java.awt.GridLayout(2, 1, 0, 5));

        jPanel6.setBorder(new javax.swing.border.TitledBorder("Protocol"));
        jLabel3.setText("Select Protocol:");
        jPanel6.add(jLabel3);

        tcpSelectionBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CharGen", "Daytime", "Echo", "Finger", "FTP", "NNTP", "POP3", "SMTP", "Time", "Whois" }));
        tcpSelectionBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tcpSelectionBoxActionPerformed(evt);
            }
        });

        jPanel6.add(tcpSelectionBox);

        jPanel5.add(jPanel6);

        jPanel3.setBorder(new javax.swing.border.TitledBorder("Server Connection Details"));
        jLabel1.setText("Server:");
        jPanel3.add(jLabel1);

        serverNameField.setColumns(25);
        jPanel3.add(serverNameField);

        jLabel2.setText("Port:");
        jPanel3.add(jLabel2);

        portNumberField.setColumns(4);
        portNumberField.setText("19");
        jPanel3.add(portNumberField);

        tcpConnectButton.setText("CONNECT");
        tcpConnectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tcpConnectButtonActionPerformed(evt);
            }
        });

        jPanel3.add(tcpConnectButton);

        jPanel5.add(jPanel3);

        jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);

        jTabbedPane1.addTab("TCP", jPanel1);

        jPanel2.setLayout(new java.awt.BorderLayout());

        jPanel10.setLayout(new java.awt.GridLayout(2, 0));

        jPanel8.setBorder(new javax.swing.border.TitledBorder("Protocol"));
        jLabel6.setText("Select Protocol:");
        jPanel8.add(jLabel6);

        udpSelectionBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CharGen", "Daytime", "Echo", "TFTP", "Time" }));
        udpSelectionBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                udpSelectionBoxActionPerformed(evt);
            }
        });

        jPanel8.add(udpSelectionBox);

        jPanel10.add(jPanel8);

        jPanel12.setBorder(new javax.swing.border.TitledBorder("Remote Server Details"));
        jLabel7.setText("Remote Server:");
        jPanel12.add(jLabel7);

        udpRemoteServerField.setColumns(25);
        jPanel12.add(udpRemoteServerField);

        jPanel10.add(jPanel12);

        jPanel2.add(jPanel10, java.awt.BorderLayout.NORTH);

        jPanel11.setLayout(new java.awt.BorderLayout());

        udpCommandPanel.setLayout(new java.awt.GridLayout(1, 0));

        udpCommandPanel.setBorder(new javax.swing.border.TitledBorder("Command Panel"));
        udpStartButton.setText("START");
        udpStartButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                udpStartButtonActionPerformed(evt);
            }
        });

        udpCommandPanel.add(udpStartButton);

        jPanel11.add(udpCommandPanel, java.awt.BorderLayout.NORTH);

        udpServerResponse.setEditable(false);
        udpServerResponse.setFont(new java.awt.Font("Monospaced", 0, 12));
        jScrollPane2.setViewportView(udpServerResponse);

        jPanel11.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jPanel2.add(jPanel11, java.awt.BorderLayout.CENTER);

        jTabbedPane1.addTab("UDP", jPanel2);

        getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);

        pack();
    }//GEN-END:initComponents

    private void jRadioButton26ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton26ActionPerformed
        // tftp receive a file:
        udpRemoteServer = udpRemoteServerField.getText();
        if(udpRemoteServer == null || udpRemoteServer.length() == 0) {
            showError("Please enter a remote server");
            return;
        }
        
        // get the name of the file to receive
        udpStartButton.doClick();
        
        singleValueLabel.setText("Enter file path (TFTP-Receive):");
        showDialog(singleValueDialog);
    }//GEN-LAST:event_jRadioButton26ActionPerformed

    private void jRadioButton25ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton25ActionPerformed
        // tftp send a file:
        udpRemoteServer = udpRemoteServerField.getText();
        if(udpRemoteServer == null || udpRemoteServer.length() == 0) {
            showError("Please enter a remote server");
            return;
        }
        
        // get the name of the file to send
        udpStartButton.doClick();
        
        singleValueLabel.setText("Enter file path (TFTP-Send):");
        showDialog(singleValueDialog);
    }//GEN-LAST:event_jRadioButton25ActionPerformed

    private void udpStartButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_udpStartButtonActionPerformed
        // handler for Start button for UDP:
        if(started) { // means a session has already started
            try{
                handleUDPStop();
            }catch(IOException ex) {
                showError(ex.getMessage());
            }
            return;
        }
        
        udpRemoteServer = udpRemoteServerField.getText();
        
        if(udpRemoteServer == null || udpRemoteServer.length() == 0) {
            showError("Please enter a remote server");
            return;
        }

        try{
            udpClient = 
              ClientFactory.getUDPClientInstance(
                  udpSelectionBox.getSelectedIndex());
            udpClient.open();
        }catch(SocketException se){
            showError(se.getMessage());
            return;
        }catch(IOException ioex){
            showError(ioex.getMessage());
            return;
        }
        
        // if we come here means we have opened a port
        started = true;
        udpStartButton.setText("Stop");
        udpSelectionBox.setEnabled(false);
        jTabbedPane1.setEnabledAt(0, false);
        
        try {
            ProtocolHandler.handleUDPProtocol(
                udpSelectionBox.getSelectedIndex(), 
                udpClient, 
                this);
        }catch (IOException io) {
            showError(io.getMessage());
            io.printStackTrace();
        }        
        
        
    }//GEN-LAST:event_udpStartButtonActionPerformed

    private void jRadioButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton9ActionPerformed
        // reset for pop3:
        if(!checkValidConnection()) return;
        try {
            ((POP3Client)tcpClient).reset();
            tcpServerResponse.append(
                ((POP3Client)tcpClient).getReplyString() + 
                "
");
        }catch(IOException ioex) { showError(ioex.getMessage()); return; }        
    }//GEN-LAST:event_jRadioButton9ActionPerformed

    private void jRadioButton24ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton24ActionPerformed
        // delete message for pop3:
        if(!checkValidConnection()) return;
        
        singleValueLabel.setText("Enter message number to delete:");
        showDialog(singleValueDialog);
    }//GEN-LAST:event_jRadioButton24ActionPerformed

    private void jRadioButton23ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton23ActionPerformed
        // Retrieve message for pop3:
        if(!checkValidConnection()) return;
        
        singleValueLabel.setText("Enter message number:");
        showDialog(singleValueDialog);
    }//GEN-LAST:event_jRadioButton23ActionPerformed

    private void jRadioButton21ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton21ActionPerformed
        // list all messages for pop3:
        if(!checkValidConnection()) return;
        try {
            ((POP3Client)tcpClient).listMessages();
            tcpServerResponse.append(
                ((POP3Client)tcpClient).getReplyString() + 
                "
");
        }catch(IOException ioex) { showError(ioex.getMessage()); return; }        
    }//GEN-LAST:event_jRadioButton21ActionPerformed

    private void jRadioButton22ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton22ActionPerformed
        // status for pop3:
        if(!checkValidConnection()) return;
        try {
            ((POP3Client)tcpClient).status();
            tcpServerResponse.append(
                ((POP3Client)tcpClient).getReplyString() +
                "
");
        }catch(IOException ioex) { showError(ioex.getMessage()); return; }        
    }//GEN-LAST:event_jRadioButton22ActionPerformed

    private void jRadioButton20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton20ActionPerformed
        // logout for pop3:
        if(!checkValidConnection()) return;
        try {
            ((POP3Client)tcpClient).logout();
            tcpServerResponse.append(
                ((POP3Client)tcpClient).getReplyString() +
                "
");
            handleDisconnect();
        }catch(IOException ioex) { showError(ioex.getMessage()); return; }
    }//GEN-LAST:event_jRadioButton20ActionPerformed

    private void jRadioButton19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton19ActionPerformed
        // login for pop3:
        if(!checkValidConnection()) return; 
        showDialog(loginDialog);
    }//GEN-LAST:event_jRadioButton19ActionPerformed

    private void jRadioButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton16ActionPerformed
        // Send simple message for SMTP:
        if(!checkValidConnection()) return;
        
        variableLabel.setText("To:");
        showDialog(multipleValueDialog);
    }//GEN-LAST:event_jRadioButton16ActionPerformed

    private void jRadioButton18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton18ActionPerformed
        // logout for SMTP:
        if(!checkValidConnection()) return;
        
        try {
            ((SMTPClient)tcpClient).logout();
            tcpServerResponse.append(
                ((SMTPClient)tcpClient).getReplyString() +
                "
");
        }catch(IOException ioex) { showError(ioex.getMessage()); return; }         
    }//GEN-LAST:event_jRadioButton18ActionPerformed

    private void jRadioButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton17ActionPerformed
        // login for SMTP:
        if(!checkValidConnection()) return;
        
        // for SMTP login is simply sending HELO
        try {
            ((SMTPClient)tcpClient).login();
            tcpServerResponse.append(
                ((SMTPClient)tcpClient).getReplyString() +
                "
");
        }catch(IOException ioex) { showError(ioex.getMessage()); return; } 
        
    }//GEN-LAST:event_jRadioButton17ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // ok for multiple value dialog:
        String fromText     = fromField.getText();
        String subjectText  = subjectField.getText();
        String variableText = variableField.getText();
        String messageText  = messageArea.getText();
        
        DotTerminatedMessageWriter writer;
              
        int selection = tcpSelectionBox.getSelectedIndex();
        try{
            if(selection == 5) { // means handling NNTP posting of message
                writer = (DotTerminatedMessageWriter)
                    ((NNTPClient)tcpClient).postArticle();             
                
                if(writer == null) { 
                    tcpServerResponse.append(
                        ((NNTPClient)tcpClient).getReplyString() + "
");
                    return;
                }
                
                // create simple NNTP headers
                SimpleNNTPHeader headers = 
                    new SimpleNNTPHeader(fromText, subjectText);
                headers.addNewsgroup(variableText);
                
                // and write the message on
                writer.write(headers.toString());
                writer.write(messageText);
                writer.close();
                ((NNTPClient)tcpClient).completePendingCommand();                
                tcpServerResponse.append(
                    ((NNTPClient)tcpClient).getReplyString() + "
");                
            } else if(selection == 7) { // means handling SMTP posting of message
                
                ((SMTPClient)tcpClient).setSender(fromText);
                ((SMTPClient)tcpClient).addRecipient(variableText);

                writer = (DotTerminatedMessageWriter) 
                    ((SMTPClient)tcpClient).sendMessageData();                
                
                if(writer == null) {
                    tcpServerResponse.append(
                        ((SMTPClient)tcpClient).getReplyString() + "
");
                    return;
                }
                
                // create Simple SMTP header
                SimpleSMTPHeader headers = 
                    new SimpleSMTPHeader(fromText, variableText, subjectText);
                
                writer.write(headers.toString());
                writer.write(messageText);
                writer.close();
                ((SMTPClient)tcpClient).completePendingCommand();
                tcpServerResponse.append(
                    ((SMTPClient)tcpClient).getReplyString() + "
");                
            }
        }catch(IOException ioex) { showError(ioex.getMessage()); }
        finally{ 
            fromField.setText(""); 
            subjectField.setText(""); 
            variableField.setText(""); 
            messageArea.setText("");
            multipleValueDialog.setVisible(false);
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // cancel for multiple value dialog:
        multipleValueDialog.setVisible(false);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jRadioButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton13ActionPerformed
        // post article for nntp:
        if(!checkValidConnection()) return;
        
        variableLabel.setText("Newsgroup:");
        showDialog(multipleValueDialog);
    }//GEN-LAST:event_jRadioButton13ActionPerformed

    private void jRadioButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton14ActionPerformed
        // get article for nntp:
        if(!checkValidConnection()) return;
        
        singleValueLabel.setText("Enter message id:");
        showDialog(singleValueDialog);
    }//GEN-LAST:event_jRadioButton14ActionPerformed

    private void jRadioButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton12ActionPerformed
        // list new news messages for nntp:
        if(!checkValidConnection()) return;
        
        singleValueLabel.setText("Full or part name of group:");
        showDialog(singleValueDialog);
    }//GEN-LAST:event_jRadioButton12ActionPerformed

    private void jRadioButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton15ActionPerformed
        // logout for nntp:
        if(!checkValidConnection()) return;
        
        try {
            ((NNTPClient)tcpClient).logout();
            tcpServerResponse.append(
                ((NNTPClient)tcpClient).getReplyString() + "
");
            handleDisconnect();            
        }catch(IOException ioex) { showError(ioex.getMessage()); }
    }//GEN-LAST:event_jRadioButton15ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        // list all news groups for nntp:
        if(!checkValidConnection()) return;
        
        try{
            NewsgroupInfo[] newsgroups = 
                ((NNTPClient)tcpClient).listNewsgroups();
            tcpServerResponse.append(
                ((NNTPClient)tcpClient).getReplyString() + "
");
            for(int i=0; i<newsgroups.length; i++) {
                tcpServerResponse.append(newsgroups[i].getNewsgroup() + "
");
            }
        }catch(IOException ioex) { showError(ioex.getMessage()); }        
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jRadioButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton11ActionPerformed
        // list new news group for nntp:
        if(!checkValidConnection()) return;
        
        // create a query to find new news groups since yesterday
        GregorianCalendar today = new GregorianCalendar();    
        today.roll(Calendar.DAY_OF_YEAR, false);
        NewGroupsOrNewsQuery query = 
          new NewGroupsOrNewsQuery(today, false);
        
        try{
            NewsgroupInfo[] newsgroups = 
                ((NNTPClient)tcpClient).listNewNewsgroups(query);
            tcpServerResponse.append(
                ((NNTPClient)tcpClient).getReplyString() + "
");
            
            if(newsgroups == null) return;
            for(int i=0; i<newsgroups.length; i++) {
                tcpServerResponse.append(newsgroups[i].getNewsgroup() + "
");                
            }
            if(newsgroups.length == 0)
                tcpServerResponse.append("No new NewsGroups
");            
        }catch(IOException ioex) { showError(ioex.getMessage()); }      
        
    }//GEN-LAST:event_jRadioButton11ActionPerformed

    private void jRadioButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton10ActionPerformed
        // login for nntp:
        if(!checkValidConnection()) return; 
        showDialog(loginDialog);
    }//GEN-LAST:event_jRadioButton10ActionPerformed

    private void jRadioButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton7ActionPerformed
        // Download file for FTP:
        if(!checkValidConnection()) return;
        
        singleValueLabel.setText("Remote fil