Question: How do I use action event (and/or actionevent listener) in Java? Right now I have this. public void actionPerformed( ActionEvent arg0 ) { } Where

How do I use action event (and/or actionevent listener) in Java? Right now I have this. public void actionPerformed( ActionEvent arg0 ) { }

Where arg0 will be the button pressed. This project is a implementing a Calculator. So the buttons would be: "7", "8", "9", "+", "4", "5", "6", "- ", "1", "2", "3", "*", "0", "^", "=", "/", "(", ")", "C", "CE" Which are all implemented on the GUI already, with the operators and the C, CE buttons already having their own classes and stored in a hashmap.

So, for the actionevent listener, How should I implement it? When a button is pressed, how do I store the string that was pressed? And how to call the hashmap function when a button is pressed?

Example: 1. A "1" is pressed, then "+" is pressed, then "1" is pressed, then "=" is pressed. 2. If a number is pressed, how to convert that string into an integer? 3. And then how to implement that integer with the Addition() function? (Addition.java exists, containing Class Addition{} ) 4. How would you implement the "=" class?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!