My code snippet is below:
static int i=0;
JButton ar[]=new JButton[5];
for( i=0;i<5;i++)
{
ar[i]=new JButton(" Button number : "+i);
ar[i].addActionListener((ActionEvent clicked) -> {
System.out.println(" Clickevent detected on JButton number "+i);
});
panel.add(ar[i]);
In output of program , it is printing "Clickevent detected on JButton number 5" in every instance, I have no idea why this is happening.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…