pl/mbogusz3/invaders/view/InvadersView.java
/**
	 * Draw obstacles. Called from update().
	 * @param paneInsets insets of main content pane.
	 * @param paneSize size of main content pane.
	 */
Draw obstacles. Called from update().
@param paneInsets insets of main content pane.
@param paneSize size of main content pane.
Draw obstacles . Called from update () . @param paneInsets insets of main content pane . @param paneSize size of main content pane .
private void drawObstacles(Insets paneInsets, Dimension paneSize) {
		int obstacleCount = this.model.getObstacles().getCount();
		if(this.obstacles == null) {
			this.obstacles = new JLabel[obstacleCount];
			for(int i = 0; i < obstacleCount; i++) {
				this.obstacles[i] = new JLabel("");
				this.contentPane.add(this.obstacles[i]);
				this.obstacles[i].setOpaque(true);
				this.obstacles[i].setBackground(new Color(0, 207, 51));
				this.obstacles[i].setVerticalAlignment(JLabel.CENTER);
				this.obstacles[i].setHorizontalAlignment(JLabel.CENTER);
			}
		}
		if(!this.model.isGameRunning()) {
			for(int i = 0; i < obstacleCount; i++) {
				this.obstacles[i].setVisible(false);
			}
			return;
		}
		double obstacleSpacerWidth = (paneSize.width / (2 * obstacleCount + 1));
		for(int i = 0; i < obstacleCount; i++) {
			int state = this.model.getObstacles().getState()[i];
			if(state == 0) {
				this.obstacles[i].setVisible(false);
				continue;
			} else {
				this.obstacles[i].setVisible(true);
			}
			double obstaclePositionLeft = obstacleSpacerWidth * (2 * i + 1) + paneInsets.left;
			double obstaclePositionTop = 0.8 * paneSize.height + paneInsets.top;
			this.obstacles[i].setText(Integer.toString(state));
			this.obstacles[i].setBounds((int)(obstaclePositionLeft), (int)(obstaclePositionTop), (int)(obstacleSpacerWidth), (int)(0.1 * paneSize.height));
		}
	}
private void drawObstacles ( Insets paneInsets , Dimension paneSize ) { int obstacleCount = this . model . getObstacles ( ) . getCount ( ) ; if ( this . obstacles == null ) { this . obstacles = new JLabel [ obstacleCount ] ; for ( int i = 0 ; i < obstacleCount ; i ++ ) { this . obstacles [ i ] = new JLabel ( "" ) ; this . contentPane . add ( this . obstacles [ i ] ) ; this . obstacles [ i ] . setOpaque ( true ) ; this . obstacles [ i ] . setBackground ( new Color ( 0 , 207 , 51 ) ) ; this . obstacles [ i ] . setVerticalAlignment ( JLabel . CENTER ) ; this . obstacles [ i ] . setHorizontalAlignment ( JLabel . CENTER ) ; } } if ( ! this . model . isGameRunning ( ) ) { for ( int i = 0 ; i < obstacleCount ; i ++ ) { this . obstacles [ i ] . setVisible ( false ) ; } return ; } double obstacleSpacerWidth = ( paneSize . width / ( 2 * obstacleCount + 1 ) ) ; for ( int i = 0 ; i < obstacleCount ; i ++ ) { int state = this . model . getObstacles ( ) . getState ( ) [ i ] ; if ( state == 0 ) { this . obstacles [ i ] . setVisible ( false ) ; continue ; } else { this . obstacles [ i ] . setVisible ( true ) ; } double obstaclePositionLeft = obstacleSpacerWidth * ( 2 * i + 1 ) + paneInsets . left ; double obstaclePositionTop = 0.8 * paneSize . height + paneInsets . top ; this . obstacles [ i ] . setText ( Integer . toString ( state ) ) ; this . obstacles [ i ] . setBounds ( ( int ) ( obstaclePositionLeft ) , ( int ) ( obstaclePositionTop ) , ( int ) ( obstacleSpacerWidth ) , ( int ) ( 0.1 * paneSize . height ) ) ; } }
Draw obstacles.
Draw obstacles .
// First-time init of obstacles - we don't know their count before the game begins and first update comes