@Override public void run() { Color originalColor = spaceToBlink.getColor(); Color blinkColor = (spaceToBlink.getScoreModifier() < 0) ? Color.RED : Color.GREEN; Graphics2D g2d = (Graphics2D) this.getGraphics(); for (int i = 0; i < 5; i++) { g2d.setColor(blinkColor); g2d.fillRect( spaceToBlink.getPoint().x, spaceToBlink.getPoint().y, getSpaceWidth(), getSpaceHeight()); for (GamePiece pce : gamePieces) pce.repaint(); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } g2d.setColor(originalColor); g2d.fillRect( spaceToBlink.getPoint().x, spaceToBlink.getPoint().y, getSpaceWidth(), getSpaceHeight()); for (GamePiece pce : gamePieces) pce.repaint(); } Font font = new Font("Serif", Font.PLAIN, 20); g2d.setFont(font); g2d.setColor(Color.WHITE); g2d.drawString( spaceToBlink.getName(), spaceToBlink.getPoint().x, spaceToBlink.getPoint().y + (getSpaceHeight() / 2)); }
public void setPiece(GamePiece piece) { inUseModel.clear(); while (piece instanceof Decorator) { final Class<?> pieceClass = piece.getClass(); inUseModel.insertElementAt(piece, 0); boolean contains = false; for (int i = 0, j = availableModel.size(); i < j; ++i) { if (pieceClass.isInstance(availableModel.elementAt(i))) { contains = true; break; } } if (!contains) { try { availableModel.addElement(pieceClass.getConstructor().newInstance()); } catch (Throwable t) { ReflectionUtils.handleNewInstanceFailure(t, pieceClass); } } piece = ((Decorator) piece).piece; } if (piece == null) { inUseModel.insertElementAt(new BasicPiece(), 0); } else { inUseModel.insertElementAt(piece, 0); } inUseList.setSelectedIndex(0); refresh(); }