我在内部类中调用封闭类方法,但出现语法错误。这是代码:
public class Horizon
{
....
public void checkWinner()
{
if(x[1]==1 && x[2]==1 && x[3]==1 || x[4]==1 && x[5]==1 && x[6]==1 || x[7]==1 && x[8]==1 && x[9]==1)
{
JOptionPane.showMessageDialog(null, "Congratulations!\n Player 1 won!", "Congratulations",JOptionPane.OK_OPTION);
}
}
private class HandlerClass implements MouseListener
{
public void mouseClicked(MouseEvent event)
{
if(event.getSource()==lb1)
{
if(j==1)
x[1]=1;
else
x[1]=2;
lb1.setIcon(icon);
}
public void mousePressed(MouseEvent event){}
public void mouseEntered(MouseEvent event){}
public void mouseReleased(MouseEvent event){}
public void mouseExited(MouseEvent event){} // error here
Horizon.this.checkWinner();
if(i==9)
{
JOptionPane.showMessageDialog(null, "The game is a draw", "Draw", JOptionPane.OK_OPTION);
}
}
}
}
删除方法调用后错误消失。
这个错误的原因是什么,我该如何解决?问候