JAVA自动帧生成器
我试图创建一个垃圾邮件的帧,我想停止它时,我按下主键,但它不集中在第一帧(我可以使用keylistener上)。我尝试不使用第一帧,只使用循环中焦点设置为true的帧,但仍然不起作用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
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程序员。