but you would be better to create a private or package-private class which implements ActionListener and encapsulates the number too.
omar al kababji wrote:i think if you implement your calculator using Campbell Ritchie hint it will be easiear for you, even if the first option seems easier. ;)
Campbell Ritchie wrote:
But I disagree with Olly's suggestion of using JButtons as the source, for at least two reasons:
- There is no need to cast; a Button is a Component, and the == operator will work happily on objects of different classes.
- Using this sort of selection isn't object-oriented programming. You should have a value 1 associated with button1 and 2 associated with button2.
But using the titles button1 button2 may be bad style:
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton