Computer Science Canada

How to use an integer into a drawString command

Author:  ZZK [ 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);

Author:  TerranceN [ Sat Jan 01, 2011 11:33 am ]
Post subject:  RE:How to use an integer into a drawString command

A quick look at <a href="http://download.oracle.com/javase/1.4.2/docs/api/overview-summary.html">Java's documentation</a> yields <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Graphics.html#setFont(java.awt.Font)">this</a> method of the Graphics class.

Author:  copthesaint [ 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()

Author:  TerranceN [ 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 Embarassed.

Author:  ZZK [ 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.

Author:  copthesaint [ 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 Smile not a command. Dont confuse others Razz

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.


: