如何使用mouseclick侦听器获取JLabel的2D数组的索引?
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");
}
答案 0 :(得分:3)
evt.getSource()
jLabel
数组,直到源== x&amp; y co-ords