public void gameover() { ImageIcon bombss = new ImageIcon("bomb.png"); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (bombs[i][j] == true) { gbuttons[i][j].setBackground(Color.red); gbuttons[i][j].setIcon(bombss); } } } int delay = 2000; // milliseconds ActionListener taskPerformer = new ActionListener() { public void actionPerformed(ActionEvent evt) { Lost lost = new Lost(); lost.setLocationRelativeTo(null); lost.setVisible(true); dispose(); } }; Timer timer = new Timer(delay, taskPerformer); timer.setRepeats(false); timer.start(); }
@Override @SuppressWarnings("deprecation") public void hide() { if (isExperimentalSheet()) { OSXSheetSupport.hideSheet(this); hide0(); uninstallSheet(); } else if (isAnimated() && isShowAsSheet() && !isNativeSheetSupported()) { getContentPane().setVisible(false); final Rectangle startBounds = getBounds(); int parentWidth = getParent().getWidth(); final Rectangle endBounds = new Rectangle( (parentWidth < startBounds.width) ? startBounds.x + (startBounds.width - parentWidth) / 2 : startBounds.x, startBounds.y, Math.min(startBounds.width, parentWidth), 0); final Timer timer = new Timer(20, null); timer.addActionListener( new ActionListener() { long startTime; long endTime; public void actionPerformed(ActionEvent evt) { long now = System.currentTimeMillis(); if (startTime == 0) { startTime = now; endTime = startTime + 200; } if (now > endTime) { timer.stop(); hide0(); setBounds(startBounds); getContentPane().setVisible(true); uninstallSheet(); } else { float ratio = (now - startTime) / (float) (endTime - startTime); setBounds( (int) (startBounds.x * (1f - ratio) + endBounds.x * ratio), (int) (startBounds.y * (1f - ratio) + endBounds.y * ratio), (int) (startBounds.width * (1f - ratio) + endBounds.width * ratio), (int) (startBounds.height * (1f - ratio) + endBounds.height * ratio)); } } }); timer.setRepeats(true); timer.setInitialDelay(5); timer.start(); } else { hide0(); uninstallSheet(); } }
public GameCanvas() { super(true); Timer runLoopTimer = new Timer( 1000 / 60, (action) -> { if (this .shouldPlayMoveSequence()) { // Update only if we're animating the player's // movement. this.update(1000 / 60); this.repaint(); } }); runLoopTimer.setRepeats(true); runLoopTimer.start(); this.addMouseListener( new MouseListener() { @Override public void mouseClicked(MouseEvent e) { double width = GameCanvas.this.getWidth(); double height = GameCanvas.this.getHeight(); Board board = _gameState.board; double ratio = (double) board.width / board.height; width = Math.min(width, (height * ratio)); height = Math.min(height, (width / ratio)); double startX = GameCanvas.this.getWidth() / 2 - width / 2; double startY = GameCanvas.this.getHeight() / 2 - height / 2; double step = width / board.width; int tileX = (int) ((e.getX() - startX) / step); int tileY = (int) ((e.getY() - startY) / step); if (_tileSelectionDelegate.isPresent() && tileX >= 0 && tileX < board.width && tileY >= 0 && tileY < board.height) { _tileSelectionDelegate.get().didSelectTileAtLocation(new Location<>(tileX, tileY)); } } @Override public void mousePressed(MouseEvent e) {} @Override public void mouseReleased(MouseEvent e) {} @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseExited(MouseEvent e) {} }); }
private void initTimer() { timer = new Timer( 50, new ActionListener() { public void actionPerformed(ActionEvent e) { animateOneFrame(); } }); timer.setRepeats(true); }
private void refreshDisplay() { Timer timer = new Timer( 40, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { revalidate(); repaint(); } }); timer.setRepeats(true); timer.setCoalesce(true); timer.start(); }
/** Creates a timer if one doesn't already exist, then starts the timer thread. */ private void start(int interval) { previousDelay = interval; lastCall = 0; if (timer == null) { timer = new Timer(interval, this); } else { timer.setDelay(interval); } if (ADJUSTTIMER) { timer.setRepeats(false); timer.setCoalesce(false); } timer.start(); }
public void mouseMoved(MouseEvent e) { if (enabled && enableMouseMoves && !readOnly) { if (timer == null) { timer = new Timer(mouseMoveDelay, this); timer.setRepeats(false); timer.start(); } else { timer.stop(); timer.start(); } lastMouseMoveEvent = e; mouseMovesList.add(0, e); if (mouseMovesList.size() > mouseMoveInsertPrevious) { mouseMovesList.remove(mouseMovesList.size() - 1); } } }
@Override @SuppressWarnings("deprecation") public void show() { if (isExperimentalSheet()) { // Install the sheet installSheet(); // Create the native peer - maybe not supported addNotify(); if (OSXSheetSupport.showAsSheet(this)) { // Tell lightweight components to be visible show0(); return; } else { isExperimentalSheet = false; } } if (isAnimated() && isShowAsSheet() && !isNativeSheetSupported()) { installSheet(); getContentPane().setVisible(false); final Rectangle endBounds = getBounds(); int parentWidth = getParent().getWidth(); final Rectangle startBounds = new Rectangle( (parentWidth < endBounds.width) ? endBounds.x + (endBounds.width - parentWidth) / 2 : endBounds.x, endBounds.y, Math.min(endBounds.width, parentWidth), 0); setBounds(startBounds); if (!isDocumentModalitySupported()) { ((Window) getParent()).toFront(); } final Timer timer = new Timer(20, null); timer.addActionListener( new ActionListener() { long startTime; long endTime; public void actionPerformed(ActionEvent evt) { long now = System.currentTimeMillis(); if (startTime == 0) { startTime = now; endTime = startTime + 200; } if (now > endTime) { timer.stop(); setBounds(endBounds); getContentPane().setVisible(true); Component c = getFocusTraversalPolicy().getInitialComponent(JSheet.this); if (c != null) { c.requestFocus(); } else { getContentPane().requestFocus(); } } else { float ratio = (now - startTime) / (float) (endTime - startTime); setBounds( (int) (startBounds.x * (1f - ratio) + endBounds.x * ratio), (int) (startBounds.y * (1f - ratio) + endBounds.y * ratio), (int) (startBounds.width * (1f - ratio) + endBounds.width * ratio), (int) (startBounds.height * (1f - ratio) + endBounds.height * ratio)); } } }); timer.setRepeats(true); timer.setInitialDelay(5); timer.start(); show0(); } else { installSheet(); show0(); } OSXApplication.requestUserAttention(true); }