This discussion is archived
0 Replies Latest reply: Oct 8, 2009 1:49 PM by 807575 RSS

passing value from JDialog screen to calling...HELP

807575 Newbie
Currently Being Moderated
Ok I am kinda new to Java. I have minimal experience with Java and Netbeans. I am trying to capture some input results and pass them back to the calling program when I hit OK on the screen. I am not sure what to do. I got a lot of parts for my bigger program but I am not sure how to put it all together since they are not interacting as I expect them to. The part I am talking about is a critical part to the function of the rest.

Thank you for all of the help

Here is teh code that I have for the JDialog component.
import java.awt.Color;
public class IPAddressAdd extends javax.swing.JDialog {
    String ipport = null;
    public static final int RET_CANCEL = 0;
    public static final int RET_OK = 1;
    public IPAddressAdd(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    public int getReturnStatus() {
        return returnStatus;
    }
    @SuppressWarnings("unchecked")
       private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String id1 = new String(jTextField1.getText());
        String port1 = new String(jTextField2.getText());
        String blank = "";
        if (id1.equals(blank)){
            jLabel3.setText("Error: IP Address Need to be Entered");
            jLabel3.setForeground(Color.red);
            System.out.println("IP address needs to be entered.");
            return ;
        }
        if (jRadioButton1.isSelected() == true){
            pgm2Run="Receive";
            ipport = id1+"/"+port1;
        }
        else{
            pgm2Run="Transmit";
            ipport = id1+" "+port1;
        }
        doClose(RET_OK);
    }                                        

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        doClose(RET_CANCEL);
    }                                            

    private void closeDialog(java.awt.event.WindowEvent evt) {                             
        doClose(RET_CANCEL);
    }                            

    private void doClose(int retStatus) {
        returnStatus = retStatus;
        setVisible(false);
        dispose();
    }
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                IPAddressAdd dialog = new IPAddressAdd(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JButton okButton;
    private String pgm2Run;
    private int returnStatus = RET_CANCEL;
}