Help inserting contents of a string array into a JPanel

Working on a project for school and have it a road block, being spring break all the normal avenues for help and currently cutoff. SI's probably in Tijuana or something.

Anyway, project is a simple game. At the begining I ask for player information and prompt for more players.

I have setup in my GUI using border layout and intend to place the player info in the north.
I'm thinking I need to use a JTextarea for this maybe.

heres a snipet of the code I am working with so far.

                  super();
                  do
                  {
                        String playerName = JOptionPane.showInputDialog("Please Enter the Players Name.");
                        String age = JOptionPane.showInputDialog("Enter the Players Age.");
                        int playerAge = Integer.parseInt(age);
                        int playerScore = 0;
                        // Enter Player into Player Array
                        playerArray [lastPlayer] = new Players ( playerName, playerAge, playerScore );
                        prompt = JOptionPane.showConfirmDialog(null,"Add another Player?");
                  } while( prompt == JOptionPane.YES_OPTION );

I am at a loss for how to get it placed into the north field.
reefcrazedAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Provide a toString method for your Players class and then

textArea.append(playerArray [lastPlayer].toString());
CEHJCommented:
Or

textArea.append(playerArray [lastPlayer].toString() + "\n");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
reefcrazedAuthor Commented:
I'll give that a try thanks.
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

reefcrazedAuthor Commented:
Still having a bit of trouble. Rather than a snippet, here is the code.
I do have a toString made in the players class.
I made a JTextArea at the top.
I do have other issues but this one is the most pressing atm.

      public class GameGUI extends JFrame implements ActionListener
      {
            JPanel imagePanel;                                    // Panel for the images on buttons.
            JTextArea playerInfo;                              // JTextArea for Player Information.
            JButton [] imageButton;                              // Array of buttons to hold images.
            ImageIcon []imageOnButton;                        // Array of imageIcons.
            Players [] playerArray = new Players [10];// Array for Player information.
            ImageIcon imageNull;                              // Null image for blank button.
            int status =1;                                          // Flag for when button selected.
            int indexOfFirst = 0;                              // Temp index for image comparison.
            int lastPlayer = 0;
            int prompt;
                        
            // Array of image file names to be used to create imageIcons to be shown on
            // the buttons.
            String [] images = {"apple.gif", "ball.gif", "bannana.gif", "bear.gif", "bird.gif", "bug.gif",
                        "butterfly.gif", "cake.gif", "cat.gif", "dog.gif", "doll.gif", "dragon.gif", "duck.gif",
                        "elephant.gif", "fish.gif", "flower.gif", "frog.gif", "gift.gif", "hat.gif", "hotdog.gif",
                        "jackinthebox.gif", "keys.gif", "pizza.gif", "plane.gif", "rabbit.gif", "rocket.gif",
                        "rockinghorse.gif", "shoe.gif", "skateboard.gif", "snail.gif", "squirrel.gif", "sun.gif",
                        "apple.gif", "ball.gif", "bannana.gif", "bear.gif", "bird.gif", "bug.gif",
                        "butterfly.gif", "cake.gif", "cat.gif", "dog.gif", "doll.gif", "dragon.gif", "duck.gif",
                        "elephant.gif", "fish.gif", "flower.gif", "frog.gif", "gift.gif", "hat.gif", "hotdog.gif",
                        "jackinthebox.gif", "keys.gif", "pizza.gif", "plane.gif", "rabbit.gif", "rocket.gif",
                        "rockinghorse.gif", "shoe.gif", "skateboard.gif", "snail.gif", "squirrel.gif", "sun.gif"};
            Container container;
            public GameGUI()
            {      
                  super();
                  do
                  {
                        String playerName = JOptionPane.showInputDialog("Please Enter the Players Name.");
                        String age = JOptionPane.showInputDialog("Enter the Players Age.");
                        int playerAge = Integer.parseInt(age);
                        int playerScore = 0;
                        // Enter Player into Player Array
                        playerArray [lastPlayer] = new Players ( playerName, playerAge, playerScore );
                        //playerInfo.append(playerArray [lastPlayer].toString() + "\n");
                        prompt = JOptionPane.showConfirmDialog(null,"Add another Player?");
                  } while( prompt == JOptionPane.YES_OPTION );
                  
                  container = getContentPane();
                  JPanel southLayout = new JPanel();
                  JPanel northLayout = new JPanel();
                  JPanel border = new JPanel(new BorderLayout ());
                  southLayout.setLayout(new FlowLayout());
                  southLayout.add(new JButton("Start New Game"));
                  southLayout.add(new JButton("Exit"));
                  
                  playerInfo = new JTextArea(100,100);
                  northLayout.setLayout (new FlowLayout());
                  northLayout.add( new JScrollPane());
                        
                  JPanel imageGrid = new JPanel();
                  imageGrid.setLayout(new GridLayout(8,8,3,3));
                  imageButton = new JButton[64];
                  imageOnButton = new ImageIcon[64];
                        
                  for (int i =0; i < images.length; i++)              
                  {
                        imageButton[i] = new JButton(""+i);             // Create the array of buttons.
                        imageButton[i].addActionListener(this);                  // Add the listener for button clicks.
                        imageGrid.add(imageButton[i]);                              // Add the buttons to the panel.
                        imageOnButton[i] = new ImageIcon(images[i]);      // Create the array of imageIcons.
                        scramble (imageButton);
                  }      
                  
                  border.add(northLayout,BorderLayout.NORTH);
                  border.add(imageGrid,BorderLayout.CENTER);
                  border.add(southLayout,BorderLayout.SOUTH);
                        
                  imageNull = new ImageIcon("");
                  container.add(border);
                  setSize(800,800);
                  setVisible(true);
            }
            public void actionPerformed(ActionEvent event)
            {
                  for (int i = 0; i < images.length; i++)
                  {
                        if ((event.getSource()== imageButton[i])&& status==1)
                        {
                              imageButton[i].setIcon(imageOnButton[i]);
                              indexOfFirst = i;
                              status = 2;
                        }
                        else if ((event.getSource()== imageButton[i])&& status == 2)
                        {
                              imageButton[i].setIcon(imageOnButton[i]);
                        System.out.println(" "+i+" "+images[i]+" "+indexOfFirst+" "+ images[indexOfFirst]);
                              if(images[i]==(images[indexOfFirst]))
                              {
                                    JOptionPane.showMessageDialog(null,"Match");
                                    // Add point to player
                              }
                              else
                              {
                                    JOptionPane.showMessageDialog(null,"Try Again");
                                    imageButton[i].setIcon(imageNull);
                                    imageButton[indexOfFirst].setIcon(imageNull);
                                    // Switch to next player
                              }
                              status = 1;
                        }
                  }      
            }// End actionPerformed.
            public static void scramble(JButton array[])
             {
                for (int i = 0; i < array.length; i++)
                {
                   swap(array, (int)(Math.random()* 64), (int)(Math.random()* 64));
                }
             }
            public static void swap(JButton array[], int firstElement, int secondElement)
             {
                JButton temp = array[firstElement];
                array[firstElement] = array[secondElement];
                array[secondElement] = temp;
             }
      public static void main(String[] args)
      {      
            GameGUI application = new GameGUI();
            application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }//End main.
}// End JFrame.
CEHJCommented:
You'd be better to build your gui first and then add Players to it
reefcrazedAuthor Commented:
Rather than prompt at the beginning?
CEHJCommented:
Yes
reefcrazedAuthor Commented:
Moved the code for the players and removed northLayout.setLayout (new FlowLayout());

I now have something there to work with, thanks!
CEHJCommented:
:-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.