Results 1 to 11 of 11
- 12-29-2008, 06:59 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 31
- Rep Power
- 0
print variable with paint(Graphics g) ??
How does one print a number to the screen it is easy to print a string, I have tried many option but they only give a error. and I tried to find a answer with google (that is hopeless sometimes)
The above works (or should do) but the code below is one option I tried that does not workPHP Code:public void paint(Graphics g){ Font type = new Font("Monospaced", Font.BOLD, 30); g.setFont(type); String test = "something"; g.drawString(test, 10, 100); }
PHP Code:public void paint(Graphics g){ Font type = new Font("Monospaced", Font.BOLD, 30); g.setFont(type); Int test = 1234; g.drawInt(test, 10, 100); }
while I was making this thread I came up with a idea why not make a function
lets call it showInt() and return a variable I want printed, then have
g.drawString(showInt(test), 10, 100);
I must try it later.Last edited by tghn2b; 12-29-2008 at 07:03 AM. Reason: This is NOT php code it is Java
- 12-29-2008, 07:09 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
drawInt?? what is this...
and Int? should be int/Integer
you simply use Integer.toString and call drawString is enough
-
I have to agree with mtyoung here. You can't just make up method names and hope and pray that one exists to match it. You have to be precise in your spelling and capitalization as the compiler is completely unforgiving.
So an that note, there is no such animal as an "Int" and no method such as "drawInt".
His recommendation to use Integer.toString(test) is also right on the money. You can also use String.valueOf(test) for the same result.
- 12-29-2008, 09:02 AM #4
Member
- Join Date
- Jan 2008
- Posts
- 31
- Rep Power
- 0
umm when I said drawInt I also meant drawInteger (that did not work either). interesting String is not shorted but the use
int variable = 1;
NOT
integer variable = 1;
so that is why I gave "drawInt"
but anyway between your answer & gogle I have
String something = Integer.toString(test);
working,
I must go back to my Java study SCJA that tells me I am wrong when in fact I am right, it worries me they might be teaching me lies.
- 12-29-2008, 09:14 AM #5
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
i think you should read the java api doc to know which functions exist in that class
- 12-29-2008, 09:30 AM #6
- 12-29-2008, 09:37 AM #7
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
sorry...
i know the wording now...
thx
- 12-29-2008, 09:43 AM #8
Member
- Join Date
- Jan 2008
- Posts
- 31
- Rep Power
- 0
I would download if I could but I go here (I can not show you because I have not made 20 posting) API.DOC is not on this page, I go backwards and forwards with google until I am sick if it and go for a rest
I spent $700 on Sun courseware you think they would of included the api.doc SDK and any other think that may be useful like NetBeans
- 12-29-2008, 09:49 AM #9
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
simply access
java.sun.com/reference/api/
to select api which you are using
- 12-29-2008, 11:14 AM #10
Member
- Join Date
- Jan 2008
- Posts
- 31
- Rep Power
- 0
I would prefer to download it, my monthly after cap broadband internet is so slow, ............... I could die of a old man waiting for the page to show up
- 12-29-2008, 12:11 PM #11
Go to Java SE Downloads and click the Download link alongside Java SE 6 Documentation
The file size is 56.16 MB. (jdk-6u10-docs.zip)
db
Similar Threads
-
passing parameters to paint mtd
By themburu in forum Java AppletsReplies: 3Last Post: 07-14-2008, 08:15 PM -
other than paint repaint
By amith in forum Java 2DReplies: 1Last Post: 07-01-2008, 11:39 PM -
Print the text file and print preview them
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:04 PM -
radio buttons and paint
By gtraylo in forum Java AppletsReplies: 1Last Post: 04-19-2008, 12:43 PM -
paint() and paintComponent()
By goldhouse in forum Java 2DReplies: 1Last Post: 07-17-2007, 03:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks