Handle button press
I'm working on a program which solves basic polynomial problems ( the addition of two polynomials , finding the roots...)
On the GUI part, though, there's something I don't really know how to implement.
I used the CardLayout and I have multiple cards ( for the addition of polynomials, the subtraction of polynomials and so on) each of them having a button.
When the button is pressed, the method which does the operation should be called.
I don't really know how to do this, how to handle the click of the button.
If you could help me a little bit, or just give me a hint, I'd be very grateful.
To learn how to use JButtons and to add ActionListeners to them, please check out these tutorials:
How to use Buttons
How to Write an ActionListener
Thank you very much for the tutorials. I read a little bit, but still I have a question regarding the card layout. How can I memorize the button from current card, in order to know which button was clicked?
The ActionEvent passsed as a parameter to your actionPerformed( ... ) method know which button was pressed but if I were you I'd register separate ActionListeners for each button.
Originally Posted by TomWaits