button1.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) {
ImageIcon img3= new ImageIcon(this.getClass().getResource(getRandomImage().getCardNo()+".jpg"));
m.setIcon(img3);
for(int j=0; j<a.length;j++){
a[j]=new JLabel();
a[j].setText("1"+j);
System.out.println("11111111111");
pcards.add(a[j]);
System.out.print(a[j].getText());
}
}
});
为什么不能在把JLabel中的元素添加到Jpanel(pcards)中,是因为是匿名内部类才不能添加么????
public void actionPerformed(ActionEvent e) {
ImageIcon img3= new ImageIcon(this.getClass().getResource(getRandomImage().getCardNo()+".jpg"));
m.setIcon(img3);
for(int j=0; j<a.length;j++){
a[j]=new JLabel();
a[j].setText("1"+j);
System.out.println("11111111111");
pcards.add(a[j]);
System.out.print(a[j].getText());
}
}
});
为什么不能在把JLabel中的元素添加到Jpanel(pcards)中,是因为是匿名内部类才不能添加么????
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货