【发布时间】:2016-05-24 16:33:51
【问题描述】:
所以基本上我有一个公共静态 void main 方法,它创建一个框架和一个级别,该级别是一个面板,然后添加到 jframe 但之后代码似乎没有检查我在 main 中的 while 循环我知道它不是因为只要框架可见就应该检查我的while循环,如果它到达这一点并且它没有,它应该在控制台窗口中打印一行。 任何帮助,将不胜感激!另外,是的,我知道打印行会弹出一个控制台窗口窗口,但实际上并没有把它放在框架中。我为此 while 语句创建了一个单独的函数,我只是将 println 用于调试目的。
public class Main extends JFrame
{
public static void main(String[]args)
{
System.out.println("LevelStart");
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
while (m2.isVisible())
{
System.out.println("If this displays something is wrong with my checkWin method");
if(l.checkWin())
{
System.out.println("If this displays something is wrong with my checkWin method");
}
}
}
}
【问题讨论】:
标签: java swing while-loop