参考代码片段:
JLabel jl = new JLabel();
JButton jb = new JButton("按钮");
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
index++;
if(index<=0){
index = 0;
}
if(index>=images.length-1){
index = images.length-1;
}
jl.setIcon(images[index]);
}
});
效果图
完整参考代码附件下载