Java hashmap with JButton and String

Hello i have a problem i have a simple app:

private JButton a,b,c,d;

private Map test= new HashMap<>()

{{

put(a,"One");

put(b,"Two");

put(c,"Three");

put(d,"Four");

}};

When i try to print it it saying is null. But when i using a loop for

for(Map.Entry e : test.entrySet())

{

JButton key = e.getKey();

String value = e.getValue();

System.out.println(key+" "+value);

key = new JButton(value);

}

Is printing only last value with null key. I have no idea why i have null keys and why is only printing one value?...

Read More »

By: StackOverFlow - Tuesday, 13 March

Related Posts