/ Published in: Java

if you want to display numbers on the screen with drawString, you need to say "" + variableName. the "" stand for an empty string, therefore you can use drawString for displaying other than string
Expand |
Embed | Plain Text
import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import javax.swing.JComponent; { { g2.fill(box); double width = box.getWidth(); double height = box.getHeight(); g2.drawString("Width : ",50,260); g2.drawString("" + width,100,260); g2.drawString("Height : ",50,270); g2.drawString("" + height,100,270); } }
You need to login to post a comment.