我有一个座位的数组,数组中有两个字符串(已选和空闲)。鼠标单击时,我想遍历数组并找到已选座位。但当我按下按钮时,它会显示:
最终的本地变量seatno无法分配, 因为它是在封闭类型中定义的。
JButton btnContinue = new JButton("Next");
btnContinue.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent arg0) {
for(int x=0;x<17;x++){
if(anArray[x]=="selected"){
seatno = anArray[x];
}
}
data page=new data(newfrom,newto,newtime,date2,seatno);
page.setVisible(true);
setVisible(false);
}
});
btnContinue.setBounds(358, 227, 62, 23);
contentPane.add(btnContinue);
seatno
变量中含有 final 关键字。 - Luiggi Mendoza