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

Recommended Answers

I hope that Objects connect and disconnect are some of JComponents with added ActionListener

Jump to Post

All 3 Replies

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.


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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.