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控制权?因为如果他们是,我想我已经知道发生了什么:) –