如何使用 mouseclick 侦听器获取二维 JLabels 数组的索引?
for (x = 0; x < 8; x++) {
for(y=0; y<8; y++){
jLabel[x][y]=new javax.swing.JLabel(blank);
jPanel1.add(jLabel[x][y]);
jLabel[x][y].addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabelMouseClicked(evt);
}
});
}
y=0;
}
private int jLabelMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("clicked");
}