Tag: delay

Swing:启用延迟按钮

private void OptionsActionPerformed(java.awt.event.ActionEvent evt) { // After clicking on button X, I want 4 other buttons to show up // in a sequential order ButtonTrue(); } public void ButtonTrue() { Audio_Options.setVisible(true); letsSleep(); Control_Options.setVisible(true); letsSleep(); Display_Options.setVisible(true); letsSleep(); Network_Options.setVisible(true); } public void letsSleep() { try { Thread.sleep(10000); } catch (InterruptedException ex) { Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex); } } […]

在libgdx游戏中设置延迟

我有一个游戏(如超级跳投,这个游戏是一个跳跃游戏),我们的角色有生命。 在与敌人发生碰撞后,他的生命减少了。 我想在1秒后计算碰撞。 我的意思是在这1秒内,如果我的角色与敌人接触,没有任何事情发生,他继续他的方式。 为此,我在我的GameScreen类中定义一个布尔变量,名为“collision”,另一个在Wolrd类中定义名称“collBirds”。 一次与敌人碰撞接触后,collBirds变为true。 但我想在1秒后将collistion改为false。 我使用System.currentTimeMillis()和“for loop”之类的东西,但没有任何反应。 我在java中不太好。 这是我的条件: if(World.collBirds == true && collition == false){ life -= 1; lifeString = “Life : ” + life; World.collBirds = false; collition = true; for (??? “need to stay here for 1 sec” ???) { collition = false; } }

Java Swing:延迟后更改文本

基本上,我有这个游戏,一旦猜到正确的答案,它开始一个新的游戏用新词。 我想显示Correct! 但三秒后,将其更改为空字符串。 我怎么做? 我的尝试: if (anagram.isCorrect(userInput.getText())) { anagram = new Anagram(); answer.setText(“CORRECT!”); word.setText(anagram.getRandomScrambledWord()); this.repaint(); try { Thread.currentThread().sleep(3000); } catch (Exception e) { } answer.setText(“”); } else { answer.setForeground(Color.pink); answer.setText(“INCORRECT!”); } 编辑: 我的解决方案 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (anagram.isCorrect(userInput.getText())) { answer.setText(“CORRECT!”); ActionListener taskPerformer = new ActionListener() { […]