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
Map.Entry
is a key and its value combined into one class. This allows you to iterate over Map.entrySet()
instead of having to iterate over Map.keySet()
, then getting the value for each key. A better way to write what you have is:
for (Map.Entry entry : listbouton.entrySet())
{
String key = entry.getKey();
JButton value = entry.getValue();
this.add(value);
}
If this wasn't clear let me know and I'll amend my answer.