In the listener for a button in the actionPerformed(ActionEvent e) part, if you call e.getSource it returns a type object. So how can I turn that object that it returns into the original button?

cast it
(JButton) e.getSource()

If you want to know whether it's button1, button2 etc, you can simply say
if (e,getSource() == button1) ...

So long as you use a period and not a comma. ;-)

Ooops! (hangs head in shame)

You can cast the button eg. (JButton) e.getSource() or make the clicked button do something eg.

            if(e.getSource == button){
            //do something
            }
Be a part of the DaniWeb community

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