How to use an integer into a drawString command
Author |
Message |
ZZK
|
Posted: Sat Jan 01, 2011 10:20 am Post subject: How to use an integer into a drawString command |
|
|
I have a counter that is counting the points the user gets when they kill the enemy, so i want to put that counter in the drawString, because i have a a custom font, i want to know how i would go about doing that. As well this is in the applet. Here is a section for my code
enemyPoints = enemyPoints + 100;
g.setColor (blue);
g.fillRect (25, 40, 120, 20);
g.setColor (Color.white);
g.setFont (Mario);
g.drawString (enemyPoints, 35, 58);
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: Sat Jan 01, 2011 11:33 am Post subject: RE:How to use an integer into a drawString command |
|
|
A quick look at Java's documentation yields this method of the Graphics class.
|
|
|
|
|
|
copthesaint
|
Posted: Sat Jan 01, 2011 8:32 pm Post subject: Re: How to use an integer into a drawString command |
|
|
What you you mean type casting ZZK?
If so then you would use this:
Java: | enemyPoints.toString() |
|
|
|
|
|
|
TerranceN
|
Posted: Sat Jan 01, 2011 8:36 pm Post subject: RE:How to use an integer into a drawString command |
|
|
Whoops misread that as how to use a custom font .
|
|
|
|
|
|
ZZK
|
Posted: Sat Jan 01, 2011 9:52 pm Post subject: Re: How to use an integer into a drawString command |
|
|
copthesaint
How would i implement that, where would i put that, and i use ready to program java, and it changes what you told me to int enemyPoints;toString (); the program runs but where i have the points it changes it to a small line.
Description: |
heres a pic of how it looks |
|
Filesize: |
31.81 KB |
Viewed: |
210 Time(s) |
|
|
|
|
|
|
|
copthesaint
|
Posted: Sat Jan 01, 2011 10:34 pm Post subject: RE:How to use an integer into a drawString command |
|
|
Before you draw this string using font variable "Mario"
Did you init this Font Object correctly?
EDIT:
PS: drawstring is a method not a command. Dont confuse others
EDIT2:
Ditch JavaRTP it should be more like JavaRIP. lol... Its the most garbage program to possibly use for java, even if it feels ohh so familiar to turing.
Learn NetBeans now and you wont have too later if you ever decide to program for a living. It takes at most 30 min to set it up if you have never done so before.
As for the .toString() method, its part of java Lang so you shouldn't have to implement anything for which.
|
|
|
|
|
|
|
|