0
所以我在我的公共靜態無效主要嵌套類。它似乎編譯和正確,但它應該執行的功能似乎並沒有執行。這是方法。動作監聽器和內部類java
public static void main(String[]args)
{
LevelOne l = new LevelOne();
//Level Two not made yet just a place holder to show constructor with a different type
LevelTwo l2 = new LevelTwo();
//I make l2 first because the front frame is the last one created
Main m = new Main(l2);
Main m2 = new Main(l);
//To switch levels i am going to load them all in advance and then when the beat the level it will close the frame
class ChoiceListener implements ActionListener
{
Timer tm = new Timer(5, this);
//timer is used for the actionlistener
public void actionPerformed(ActionEvent e)
{
if(l.checkWin())
{
m2.setVisible(false);
m2.dispose();
}
}
}
}
這裏是它應該訪問其他類中的表單級別l的變量。
public void setWin()
{
this.checkWin = true;
}
public boolean checkWin()
{
return this.checkWin;
}
checkWin是另一個類的私有實例字段。出於某種原因,當checkWin設置爲true時,它仍然不會執行。任何幫助,將不勝感激!
Main也是類的名稱這就是爲什麼建設者說主要抱歉,如果有任何混淆因此。 –
你在哪裏創建你的監聽器類的實例並使用它?你只是現在宣佈它。 – Sanjeev
這些Java Swing/AWT控制權?因爲如果他們是,我想我已經知道發生了什麼:) –