@Override public void run() { while (true) { if (istWindows()) aktuell = holeLaufwerkeWindows(); else aktuell = holeLaufwerkeUnix(); if (initial.size() != aktuell.size()) { if (!initial.containsAll(aktuell)) { neuesLaufwerk = holePathVonNeuemLaufwerk(initial, aktuell); textArea.append("Neues Laufwerk endeckt: " + neuesLaufwerk + System.lineSeparator()); this.initial = (ArrayList<Path>) aktuell.clone(); neuesLaufwerkDialog(); } else { this.initial = (ArrayList<Path>) aktuell.clone(); textArea.append("Laufwerk wurde entfernt" + System.lineSeparator()); } } try { Thread.sleep(5000); } catch (InterruptedException e) { System.out.println("Laufwerksprüfung wird abgebrochen"); } } }
@Override public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(100); } catch (Exception e) { // TODO: handle exception } // 判断每一粒子弹和每一辆敌人的坦克都是否有重合(击中) for (int i = 0; i < hero.bombs.size(); i++) { // 取出每个子弹 Bomb myBomb = hero.bombs.get(i); // 子弹必须得存活才有判断的意义 if (myBomb.isLive) { for (int j = 0; j < ets.size(); j++) { // 取出每辆坦克 EnemyTank et = ets.get(j); if (et.isLive) { this.isHit(myBomb, et); } } } } this.repaint(); } }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); Thread.sleep(delay); log("> run MouseMoveThread " + x + ", " + y); while (!hasFocus()) { Thread.sleep(1000); } int x1 = lastMouseX; int x2 = x; int y1 = lastMouseY; int y2 = y; // shrink range by 1 px on both ends // manually move this 1px to trip DND code if (x1 != x2) { int dx = x - lastMouseX; if (dx > 0) { x1 += 1; x2 -= 1; } else { x1 -= 1; x2 += 1; } } if (y1 != y2) { int dy = y - lastMouseY; if (dy > 0) { y1 += 1; y2 -= 1; } else { y1 -= 1; y2 += 1; } } robot.setAutoDelay(Math.max(duration / 100, 1)); robot.mouseMove(x1, y1); int d = 100; for (int t = 0; t <= d; t++) { x1 = (int) easeInOutQuad( (double) t, (double) lastMouseX, (double) x2 - lastMouseX, (double) d); y1 = (int) easeInOutQuad( (double) t, (double) lastMouseY, (double) y2 - lastMouseY, (double) d); robot.mouseMove(x1, y1); } robot.mouseMove(x, y); lastMouseX = x; lastMouseY = y; robot.waitForIdle(); robot.setAutoDelay(1); } catch (Exception e) { log("Bad parameters passed to mouseMove"); e.printStackTrace(); } log("< run MouseMoveThread"); }
public void appear(final CardGui card) { moving = card; player1.animations.add(moving); Thread t = new Thread( () -> { moving.setBounds(925 - 62, 609 - 93, 0, 0); int i = 0, j = 0; while (i <= 124 || j <= 186) { try { if (i <= 124) { i++; moving.setBounds(925 - 62, 609 - 93, i, j); Thread.sleep(1); } if (j <= 186) { j++; moving.setBounds(925 - 62, 609 - 93, i, j); Thread.sleep(1); } } catch (InterruptedException e) { e.printStackTrace(); } } i = 925 - 62; while (i >= 652) { i--; try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } moving.setLocation(i, 609 - 93); } player1.animations.remove(moving); player1.repairListeners(false); PlayGui.player.pdeck.textField.setText( "cards left " + PlayGui.player.pdeck.Deck.cardsLeft()); player1.cardDrawn = 1; PlayGui.player.pdeck.textField.repaint(); setVisible(true); repaint(); }); t.start(); }
public void run() { while (true) { /* loop forever */ switch (command) { case COMMAND_NONE: setTitle("None"); proxy.stop('A'); break; case COMMAND_FORWARDS: setTitle("Forwards"); direction = DIRECTION_FORWARDS; proxy.forward('A'); break; case COMMAND_BACKWARDS: setTitle("Backwards"); direction = DIRECTION_BACKWARDS; proxy.backward('A'); break; default: System.out.println("unknown command " + command); System.exit(1); } try { Thread.sleep(DELAY_MS); } catch (Exception e) { System.out.println(e); System.exit(1); } } }
/* * Animate ejecting the card that is currently inside the reader. */ void animateEjection() { setLabel("Ejecting card"); setVisible(true); Rectangle currentBounds = new Rectangle( originalBounds.x + originalBounds.width / 2, originalBounds.y + originalBounds.height / 2, originalBounds.width / originalBounds.height, 1); while (currentBounds.height <= originalBounds.height && currentBounds.width <= originalBounds.width) { setBounds(currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height); repaint(); try { Thread.sleep(100); } catch (InterruptedException e) { } currentBounds.height += 1; currentBounds.width = (originalBounds.width * currentBounds.height) / originalBounds.height; currentBounds.x = originalBounds.x + (originalBounds.width - currentBounds.width) / 2; currentBounds.y = originalBounds.y + (originalBounds.height - currentBounds.height) / 2; } setLabel("Click to insert card"); }
public String set_old_key(String keyx) { System.out.println("Build old keys"); while (network.database_in_use == 1) { int test_db = 0; System.out.println("Database in use... import key"); try { Thread.sleep(1000); } catch (InterruptedException e) { } test_db++; } // ********************************* mining.mining3 = false; krypton_database_import_keys import_kx = new krypton_database_import_keys(keyx); krypton_database_load_network xxn = new krypton_database_load_network(); krypton_database_load xxs = new krypton_database_load(); mining.mining3 = true; return network.settingsx[5]; } // **********************
public String set_new_node(String nodex) { System.out.println("Add new node"); while (network.database_in_use == 1) { int test_db = 0; System.out.println("Database in use... import node"); try { Thread.sleep(1000); } catch (InterruptedException e) { } test_db++; } // ********************************* mining.mining3 = false; krypton_database_nodes add_node = new krypton_database_nodes(nodex); krypton_database_load_network nodesx = new krypton_database_load_network(); krypton_database_load loadx = new krypton_database_load(); mining.mining3 = true; return Integer.toString(network.network_list.size()); } // **********************
public String delete_all_nodes() { System.out.println("Delete all nodes"); while (network.database_in_use == 1) { int test_db = 0; System.out.println("Database in use... delete all nodes"); try { Thread.sleep(1000); } catch (InterruptedException e) { } test_db++; } // ********************************* mining.mining3 = false; krypton_database_delete_network pxd = new krypton_database_delete_network(); krypton_database_load_network nodesx = new krypton_database_load_network(); krypton_database_load loadx = new krypton_database_load(); mining.mining3 = true; return "deleted"; } // **********************
// set max_frames to 1 for 5 seconds then move up to 200 public void run() { pg.si("frames", 1); try { Thread.sleep(5000); } catch (Exception e) { e.printStackTrace(); } for (int i = 1; i <= 100; i++) { pg.si("frames", 2 * i); try { Thread.sleep(10); } catch (Exception e) { e.printStackTrace(); } } }
public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); synchronized (this._camera) { try { gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame. NyARGLDrawUtil.drawBackGround(gl, this._camera.getSourceImage(), 1.0); this._nyar.update(this._camera); if (this._nyar.isExistMarker(this.ids[0])) { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[0]), 0); NyARGLDrawUtil.drawColorCube(gl, 40); gl.glPopMatrix(); } if (this._nyar.isExistMarker(this.ids[1])) { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[1]), 0); NyARGLDrawUtil.drawColorCube(gl, 40); gl.glPopMatrix(); } Thread.sleep(1); } catch (Exception e) { e.printStackTrace(); } } }
public void run() { // Create and add sprites to the // sprite manager spriteManager = new SpriteManager(new BackgroundImage(this, backGroundImage)); // Create 15 sprites from 6 gif // files. for (int cnt = 0; cnt < 15; cnt++) { Point position = spriteManager.getEmptyPosition( new Dimension(gifImages[0].getWidth(this), gifImages[0].getHeight(this))); spriteManager.addSprite(makeSprite(position, cnt % 6)); } // end for loop // Loop, sleep, and update sprite // positions once each 83 // milliseconds long time = System.currentTimeMillis(); while (true) { // infinite loop spriteManager.update(); repaint(); try { time += animationDelay; Thread.sleep(Math.max(0, time - System.currentTimeMillis())); } catch (InterruptedException e) { System.out.println(e); } // end catch } // end while loop } // end run method
/*This method runs the actual playing part of the game. It goes in a loop while game is true and constantly paints the game, requests the focus, checks for collisions, and checks if anyone won with a small delay. If game is false, it leaves the loop and the game is done.*/ public void game() // constantly runs update and paint world { // Loops while game is true while (game) { // Paints the game paintGame(); // Requests the focus for listening to key events window.requestFocus(); // Checks if any player has collided with anything checkCollision(); // Checks if any player has won checkWin(); // Sleeps for SPEED milliseconds try { Thread.sleep(SPEED); } // delay catch (InterruptedException e) { } // Checks if window closed. If so, game is false if (!isVisible()) { game = false; } } // Makes the mode 5 so that it still stays on the game screen after game is done mode = 5; // Paints the game once more paintGame(); }
public SplashDemo() throws NullPointerException, IllegalStateException, IOException { super("SplashScreen demo"); setSize(300, 200); setLayout(new BorderLayout()); Menu m1 = new Menu("File"); MenuItem mi1 = new MenuItem("Exit"); m1.add(mi1); mi1.addActionListener(this); this.addWindowListener(closeWindow); MenuBar mb = new MenuBar(); setMenuBar(mb); mb.add(m1); final SplashScreen splash = SplashScreen.getSplashScreen(); if (splash == null) { System.out.println("SplashScreen.getSplashScreen() returned null"); return; } Graphics2D g = splash.createGraphics(); if (g == null) { System.out.println("g is null"); return; } for (int i = 0; i < 100; i++) { renderSplashFrame(g, i); splash.update(); try { Thread.sleep(90); } catch (InterruptedException e) { } } splash.close(); setVisible(true); toFront(); }
/** * Wait for a specified number of milliseconds before finishing. This provides an easy way to * specify a small delay which can be used when producing animations. * * @param milliseconds the number */ public void wait(int milliseconds) { try { Thread.sleep(milliseconds); } catch (Exception e) { // ignoring exception at the moment } }
private void leuchten(JLabel label, String farbe) { try { if (!leuchten) { Thread.sleep(200); label.setIcon(new ImageIcon(farbe + "_0.png")); Thread.sleep(200); label.setIcon(new ImageIcon(farbe + "_1.png")); Thread.sleep(200); label.setIcon(new ImageIcon(farbe + "_0.png")); Thread.sleep(200); label.setIcon(new ImageIcon(farbe + "_1.png")); leuchten = true; } } catch (Exception e) { } }
// Not sure about what happens if multiple of this test are // instantiated in the same VM. Being static (and using // static vars), it aint gonna work. Not worrying about // it for now. public static void main(String args[]) throws InterruptedException { mainThread = Thread.currentThread(); try { init(); } catch (TestPassedException e) { // The test passed, so just return from main and harness will // interepret this return as a pass return; } // At this point, neither test pass nor test fail has been // called -- either would have thrown an exception and ended the // test, so we know we have multiple threads. // Test involves other threads, so sleep and wait for them to // called pass() or fail() try { Thread.sleep(sleepTime); // Timed out, so fail the test throw new RuntimeException("Timed out after " + sleepTime / 1000 + " seconds"); } catch (InterruptedException e) { // The test harness may have interrupted the test. If so, rethrow the exception // so that the harness gets it and deals with it. if (!testGeneratedInterrupt) throw e; // reset flag in case hit this code more than once for some reason (just safety) testGeneratedInterrupt = false; if (theTestPassed == false) { throw new RuntimeException(failureMessage); } } } // main
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); Thread.sleep(delay); log("> run MousePressThread"); while (!hasFocus()) { Thread.sleep(1000); } robot.mousePress(mask); robot.waitForIdle(); } catch (Exception e) { log("Bad parameters passed to mousePress"); e.printStackTrace(); } log("< run MousePressThread"); }
public void prompt(String msg, int delayMS) { try { Thread.sleep(delayMS); } catch (InterruptedException ie) { } prompt(msg); }
public void run() { MOVE_PREV = MOVE_DOWN; System.out.println("INIT!"); map = new int[mapX][mapY]; for (int i = 0; i < map.length; i++) { for (int j = 0; j < map[i].length; j++) { map[i][j] = 0; } } map[blockP.x][blockP.y] = 1; // map[0][20] = 1; StdDraw.setXscale(-1.0, 1.0); StdDraw.setYscale(-1.0, 1.0); // initial values // double vx = 0.015, vy = 0.023; // velocity // main animation loop while (true) { drawGame(); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } movePrev(); } }
public void run() { while (true) { try { for (Target q : targets) // Target Cycling { q.move(); // Target Movement // if(targets.get(i).getY() < 0 || targets.get(i).getY() > 490) // Target // Zones // { // targets.get(i).bounceX(); // Target Bouncing // } } // for(int i = 0; i < regions.size(); i++) // Region Cycling // { // regions.get(i).move() // Region Movement // if(regions.get(i).getY() < 0 || regions.get(i).getY() > 490) // Region Zones // { // regions.get(i).bounceX(); // Region Bouncing // } // } repaint(); t.sleep(timeStep); } catch (InterruptedException e) { } } }
public void seeCard(int num, String cardnum) { String str = "pic/starship_"; card[num].setIcon(new ImageIcon(str + cardnum + "_s.jpg")); try { Thread.sleep(2000); } catch (Exception e) { } }
public void run() { try { if (myPreviousThread != null) myPreviousThread.join(); // in different order so async works while (!hasFocus()) { Thread.sleep(1000); } Thread.sleep(delay); log("> run KeyPressThread"); _typeKey(charCode, keyCode, alt, ctrl, shift); } catch (Exception e) { log("Bad parameters passed to _typeKey"); e.printStackTrace(); } log("< run KeyPressThread"); }
private void neueFarbe() { try { if ((runde % 2) == 0 && wait > 25) { wait = wait - 25; } klick = 0; durchgang++; zahl = zufall.nextInt(4); switch (zahl) { case (0): rot.setIcon(new ImageIcon("files/Minigames/Senso/red_1.png")); soundAbspielen(soundR); einfuegen(runde, 1); Thread.sleep(wait + 25); rot.setIcon(new ImageIcon("files/Minigames/Senso/red_0.png")); break; case (1): gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_1.png")); soundAbspielen(soundG); einfuegen(runde, 2); Thread.sleep(wait + 25); gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_0.png")); break; case (2): blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_1.png")); soundAbspielen(soundB); einfuegen(runde, 3); Thread.sleep(wait + 25); blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_0.png")); break; case (3): gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_1.png")); soundAbspielen(soundY); einfuegen(runde, 4); Thread.sleep(wait + 25); gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_0.png")); break; } durchgang = 0; runde++; neu = false; kopieren(); } catch (Exception ex) { } }
public void run() { // how to let this terminate gracefully? while (1 != 2) { try { Thread.sleep(_period); updateDisplay(); } catch (InterruptedException e) { } } }
public void run() { while (true) { try { update(); Thread.sleep(5000); } catch (InterruptedException e) { } } }
void takeScreenshot() { SikuliIDE ide = SikuliIDE.getInstance(); ide.setVisible(false); try { Thread.sleep(500); } catch (Exception e) { } _simg = (new ScreenUnion()).getScreen().capture(); ide.setVisible(true); }
public void run() { while (true) { int i = (int) (Math.random() * size()); ((CBox2) elementAt(i)).nextColor(); try { t.sleep(pause * 100); } catch (InterruptedException e) { } } }
public void run() { try { for (int i = 1; i <= STEPS; i++) { ball.move(component.getBounds()); component.repaint(); Thread.sleep(DELAY); } } catch (InterruptedException e) { } }
static String waitForInputString() { try { while (!hasEntered) { Thread.sleep(100); } return inputField.getText(); } catch (Exception e) { return ""; } }