Results 1 to 11 of 11
  1. #1
    tghn2b is offline Member
    Join Date
    Jan 2008
    Posts
    31
    Rep Power
    0

    Default 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)


    PHP 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);
    }
    The above works (or should do) but the code below is one option I tried that does not work


    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

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    drawInt?? what is this...
    and Int? should be int/Integer
    you simply use Integer.toString and call drawString is enough

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  4. #4
    tghn2b is offline Member
    Join Date
    Jan 2008
    Posts
    31
    Rep Power
    0

    Default

    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.

  5. #5
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    i think you should read the java api doc to know which functions exist in that class

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

    Default

    Quote Originally Posted by mtyoung View Post
    i think you should read the java api doc to know which functions exist in that class
    Methods. Not functions.

    db

  7. #7
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  8. #8
    tghn2b is offline Member
    Join Date
    Jan 2008
    Posts
    31
    Rep Power
    0

    Default

    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

  9. #9
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    simply access
    java.sun.com/reference/api/
    to select api which you are using

  10. #10
    tghn2b is offline Member
    Join Date
    Jan 2008
    Posts
    31
    Rep Power
    0

    Default

    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

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

    Default

    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

  1. passing parameters to paint mtd
    By themburu in forum Java Applets
    Replies: 3
    Last Post: 07-14-2008, 08:15 PM
  2. other than paint repaint
    By amith in forum Java 2D
    Replies: 1
    Last Post: 07-01-2008, 11:39 PM
  3. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  4. radio buttons and paint
    By gtraylo in forum Java Applets
    Replies: 1
    Last Post: 04-19-2008, 12:43 PM
  5. paint() and paintComponent()
    By goldhouse in forum Java 2D
    Replies: 1
    Last Post: 07-17-2007, 03:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •