I\'m working on creating a calculator.
I put my buttons in a HashMap
collection and when I want to add them to my class, which extends JPanel
, I do
A Map is a collection of Key + Value pairs, which is visualized like this:
{[fooKey=fooValue],barKey=barValue],[quxKey=quxValue]}
The Map interface allows a few options for accessing this collection: The Key set [fooKey, barKey,quxKey]
, the Value set [fooValue, barValue, quxValue]
and finally entry Set [fooKey=fooValue],barKey=barValue],[quxKey=quxValue]
.
Entry set is simply a convenience to iterate over the key value pairs in the map, the Map.Entry is the representation of each key value pair. An equivalent way to do your last loop would be:
for (String buttonKey: listbouton.keySet()) {
this.add(listbouton.get(buttonKey)) ;
}
or
for (JButton button: listbouton.values()) {
this.add(button) ;
}