This JDialog sends me nuts

Hello,
Here I am giving you a JDialog. I click on any of the Radio Buttons or the Push buttons. It fires the ActionEvent as expected. I have the actionPerformed(). There I put  a print statement and I see the Event is generated by the correct button. Inside I have this statement

if (aEvt.getSource() == btnRef )
{
}

To my surprise, the aevnt.getSource() would not compare with the button reference. I am lost. I have other forms I do the same, it simply work. So here it is to the experts.

Here is the code:

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;


public class AddEmployeeDialog extends JDialog implements ActionListener
{
  private final Font textFont = new Font("SansSerif", Font.PLAIN, 12);
 

  private JTextField tfLastname, tfFirstname,
     tfSocialSecurity, tfHireDate, tfBirthDate, tfGrossSales, tfCommissionRate, tfWeeklySalary;
  JRadioButton rbWeeklySalaried, rbCommBased;


  private JButton btnSubmit, btnCancel;

  public AddEmployeeDialog ()
  {
    this.setTitle("Add New Employee");
    this.setSize(300, 350);
   
    JPanel emptypeRadiopanel = new JPanel(new GridLayout(2, 1));
    JRadioButton rbWeeklySalaried = new JRadioButton("Weekly Salaried");
    rbWeeklySalaried.addActionListener(this);
    rbWeeklySalaried.setSelected(true);
    rbWeeklySalaried.setFont(textFont);

    JRadioButton rbCommBased = new JRadioButton("Commission Based");
    rbCommBased.setFont(textFont);
    rbCommBased.addActionListener(this);
    emptypeRadiopanel.add(rbWeeklySalaried);
    emptypeRadiopanel.add(rbCommBased);

    JPanel emptypeOuterPanel = new JPanel(new GridLayout(1, 2));
    emptypeOuterPanel.add(new Label("Employee Type"));
    emptypeOuterPanel.add(emptypeRadiopanel);
     
    this.getContentPane().add(emptypeOuterPanel, BorderLayout.NORTH);

    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(rbCommBased);
    buttonGroup.add(rbWeeklySalaried);



 
   
    JPanel addEmpPanel = new JPanel(new GridLayout(8, 2));
    addEmpPanel.setBorder(BorderFactory.createLineBorder(Color.white));

    JLabel lblFirstName = new JLabel("First Name");
    lblFirstName.setFont(textFont);
    addEmpPanel.add(lblFirstName);
    tfLastname = new JTextField(60);
    addEmpPanel.add(tfLastname);
   
    JLabel lblLastName = new JLabel("Last Name");
    lblLastName.setFont(textFont);    
    addEmpPanel.add(lblLastName);
    tfFirstname = new JTextField(60);
    addEmpPanel.add(tfFirstname);

    JLabel lblSocialSecurity = new JLabel("SocialSecurity");
    lblSocialSecurity.setFont(textFont);
    addEmpPanel.add(lblSocialSecurity);
    tfSocialSecurity = new JTextField(60);
    addEmpPanel.add(tfSocialSecurity);

    JLabel lblBirthDate = new JLabel("Birth Date");
    lblBirthDate.setFont(textFont);
    addEmpPanel.add(lblBirthDate);
    tfBirthDate = new JTextField(60);
    addEmpPanel.add(tfBirthDate);
     
    JLabel lblHireDate = new JLabel("Hire Date");
    lblHireDate.setFont(textFont);
    addEmpPanel.add(lblHireDate);
    tfHireDate = new JTextField(60);  
    addEmpPanel.add(tfHireDate);

    JLabel lblWeeklySalary = new JLabel("Weekly Salary");
    lblWeeklySalary.setFont(textFont);
    addEmpPanel.add(lblWeeklySalary);
    tfWeeklySalary = new JTextField(60);  
    addEmpPanel.add(tfWeeklySalary);

    JLabel lblGrossSales= new JLabel("Gross Sales");
    lblGrossSales.setFont(textFont);
    addEmpPanel.add(lblGrossSales);
    tfGrossSales = new JTextField(60);  
    tfGrossSales.setEnabled(false);
    addEmpPanel.add(tfGrossSales);

    JLabel lblCommRate = new JLabel("Commission rate");
    lblCommRate.setFont(textFont);
    addEmpPanel.add(lblCommRate);
    tfCommissionRate = new JTextField(60);
    tfCommissionRate.setEnabled(false);
    addEmpPanel.add(tfCommissionRate);
     

    this.getContentPane().add(addEmpPanel, BorderLayout.CENTER);


    btnSubmit = new JButton("Submit");
    btnSubmit.addActionListener(this);
    btnSubmit.setFont(textFont);
   

    btnCancel = new JButton("Cancel");
    btnCancel.setFont(textFont);

    JPanel btnPanel = new JPanel();
   
    btnPanel.add(btnSubmit);
    btnPanel.add(btnCancel);

    this.getContentPane().add(btnPanel, BorderLayout.SOUTH);
  }


public void actionPerformed(ActionEvent aEvnt)
  {
System.out.println("You ain : " + aEvnt.getSource());   //This prints

    if (aEvnt.getSource() == rbWeeklySalaried) //does not evaluate
    {
System.out.println("Salaried Clicked");
 
    }


    if (aEvnt.getSource() == rbCommBased)   //does not evaluate
    {
System.out.println("Commision Clicked");
 
    }
  }

  public static void main(String [] args)
  {

    AddEmployeeDialog aed = new AddEmployeeDialog();
    aed.setVisible(true);
  }

}
prainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
>     JRadioButton rbCommBased = new JRadioButton("Commission Based");

change that to:

    rbCommBased = new JRadioButton("Commission Based");


same for the other one

you're setting a local var instead of the member var
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prainAuthor Commented:
Gee. Feel like vomiting. Ashamed of myself for  not seeing that.

Thank You.
prain
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.