私は私のpublic static void mainに入れ子クラスを持っています。コンパイルして正しいと思われるが、実行するはずの機能は実行されていないようだ。ここにその方法があります。アクションリスナと内部クラス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に設定されていても、まだ実行されません。どんな助けもありがとう!
メインはクラスの名前でもあります。その理由のためコンストラクタが主な理由を申し訳なく思うのはなぜですか? –
リスナークラスのインスタンスを作成して使用していますか?あなたは今のところそれを宣言しただけです。 – Sanjeev
これらのJava Swing/AWTコントロールはありますか?彼らがいる場合、私はすでに何が起こっているか知っていると思う:) –