//FOR the number of cells for (int cnt=0; cnt < numCells; cnt++) { //SET a character to the character at boardToLoad's index char cell = boardToLoad.charAt(cnt); //IF cell is not a valid character if (!(cell == '.' || cell == 'x' || cell == 'o' || cell == 'm' || cell == 's' || cell == '#' || cell == 'X' || cell == 'O' || cell == 'M' || cell == 'S')) { valid = false; } else { //SET tempCells[cnt] to a new JLabel tempCells[cnt] = new JLabel(); //IF the index equals ., then x, then o, etc etc for //each possible symbol in the game if (cell == '.') { //SET the cell's icon to the associated icon tempCells[cnt].setIcon(toolbarIcons[0]); } else if (cell == 'x') { tempCells[cnt].setIcon(toolbarIcons[1]); } else if (cell == 'o') { tempCells[cnt].setIcon(toolbarIcons[2]); } else if (cell == 'm') { tempCells[cnt].setIcon(toolbarIcons[3]); } else if (cell == 's') { tempCells[cnt].setIcon(toolbarIcons[4]); } else if (cell == '#') { tempCells[cnt].setIcon(toolbarIcons[5]); } else if (cell == 'X') { tempCells[cnt].setIcon(toolbarIcons[6]); } else if (cell == 'O') { tempCells[cnt].setIcon(toolbarIcons[7]); } else if (cell == 'M') { tempCells[cnt].setIcon(toolbarIcons[8]); } else if (cell == 'S') { tempCells[cnt].setIcon(toolbarIcons[9]); } } } } } //IF the input was valid and the board isnt null if (valid && boardToLoad != null) { //FOR numCells for (int cnt=0; cnt < numCells; cnt++) { //SET each cells' icon to the corresponding tempCells' icon cells[cnt].setIcon(tempCells[cnt].getIcon()); } } //ELSE IF the input wasnt valid else if (!valid) { //SET new message dialog to tell the user about invalid input JOptionPane.showMessageDialog(this,"Invalid input! Input must be 37" + " characters\nlong and contain only the following\ncharacters: " + " . x o m s # X O M S", "Invalid input",JOptionPane.ERROR_MESSAGE) ; } }