mardi 13 mai 2014

String variable suddenly becomes a combination of letter and numbers


Vote count:

0




I have an array of JLabel PlayerLabel and array of PlayerName which is intialised the following way



String [] PlayerName;
PlayerName = new String[4];
for (int i=0;i<4;i++)
{
PlayerName[i] = "None1";

}

JLabel [] PlayerLabel;

PlayerLabel = new JLabel[4];

for (int i=0;i<4;i++)
{
String num = Integer.toString(i);
String output = "Player " + num + " : " + PlayerName;

PlayerLabel[i] = new JLabel(output);
PlayerLabel[i].setForeground(Color.white);

}


I would expect the text of my JLabel to be



Player 1 : None1



Instead I am getting



Player 1 : java.lang.String;@4e9fd887



the @4e9fd887part changes to a different combination of numbers and letters everytime i restart the program .


The PlayerName is alright when i initialised it enter image description here


I have no idea why the PlayerName becomes weird when it is added at output


enter image description here


What is happening , How do i resolve this issue ??



asked 27 secs ago






Aucun commentaire:

Enregistrer un commentaire