Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA自动帧生成器_Java_Swing - Fatal编程技术网

JAVA自动帧生成器

JAVA自动帧生成器,java,swing,Java,Swing,我试图创建一个垃圾邮件的帧,我想停止它时,我按下主键,但它不集中在第一帧(我可以使用keylistener上)。我尝试不使用第一帧,只使用循环中焦点设置为true的帧,但仍然不起作用 public class Script extends JFrame { /** * */ private static final long serialVersionUID = 1L; public static boolean isTrue = true; public Script(){ a

我试图创建一个垃圾邮件的帧,我想停止它时,我按下主键,但它不集中在第一帧(我可以使用keylistener上)。我尝试不使用第一帧,只使用循环中焦点设置为true的帧,但仍然不起作用

public class Script extends JFrame {
/**
 * 
 */
private static final long serialVersionUID = 1L;
public static boolean isTrue = true;

public Script(){
    addKeyListener(new KeyAdapter(){
        public void keyPressed(KeyEvent e){
            if(e.getKeyCode() == KeyEvent.VK_HOME)
                System.exit(1);
            }
        });
    }
public static void main(String[] args) {


    JFrame frames = new Script();
    frames.setSize(300, 300);
    frames.setVisible(true);
    frames.setFocusable(true);
    frames.setLocation(800, 1000);
    frames.setDefaultCloseOperation(EXIT_ON_CLOSE);


    while(isTrue == true){

        int x = (int)(1+Math.random() * (1500-1));
        int y = (int)(1+Math.random() * (900-1));
        JFrame frame = new Script();
        frame.setVisible(true);
        frame.setFocusable(false);
        frame.setSize(300, 300);
        frame.setLocation(x, y);
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);


}


}

}不要在没有
线程的情况下使用无限while循环。sleep
@MalikBrahimi:谢谢。工作!不客气。如果可以,请在下面将我的解决方案标记为答案。我的错误是指
线程
,而不是
时间
。我是Python程序员。