Forum Stats

  • 3,816,057 Users
  • 2,259,134 Discussions
  • 7,893,374 Comments

Discussions

g.drawString is not printing the correct value in Jpanel.

g.drawString is not printing the correct value in Jpanel.

The program is few thousand lines long. So I am posting a snippet where the error occurs

String tmpStg=new String(Integer.toString(val3));System.out.format("%d %d %s %s\n",indexOfBlock,indexOfBlock1,String.valueOf(indexOfBlock1),tmpStg);g.drawString(String.valueOf(indexOfBlock1),thsXPosWithBorder+10,thsYPosWithBorder);System.out.format("%d %d %d\n",indexOfBlock,indexOfBlock1,val3);

Output of this section of the code is

0 8 8 8

0 8 8

While the values in print statement are correct. The value printed on the jpanel using g.drawString

is not correct. The g.drawString method prints 0 in the graphics panel instead of 8. The value in indexOfBlock1

is 8 and value in indexOfBlock is 0. Value in val3 is also same as value in indexOfBlock1. But if

I print it through g.drawString then it shows value as 0.