0

Dear All,
I am writing the following code but I am facing some problem.

    public void actionPerformed(ActionEvent ae)
    {
    if (ae.getSource()==connect)
        {
      JOptionPane.showMessageDialog(null, "Connection Estabilished");       
       }
      else if (ae.getSource()==disconnect)
        {
        JOptionPane.showMessageDialog(null, "Connection Disconnect");
          } 
    }

When I Write this code, compiler compile this code but does not show messagebox when i clicked on buttons...........
Anyone please help me....
I am waiting for your help
Thanks

Edited by Dani: Formatting fixed

4
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by NormR1
0

Do you have the source you can show us where you are assigning the buttons?
Make sure you are adding the action listener from both buttons. Also assuming those two objects are buttons.

connect.addActionListener(this);
disconnect.addActionListener(this);
0

Add an else at the end of the if/else if chain and have it print out the contents of the event object. That handles the case where none of the above were true.

You should always add an ending else to catch unexpected cases & problems.

Edited by NormR1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.