Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

need some java help..... *fast*

Options
  • 12-04-2001 2:38pm
    #1
    Registered Users Posts: 7,626 ✭✭✭


    how do you skip to the next line in a string?? i'm doing applets.... and the /n or whatever doesn't work.

    help please smile.gif

    - Ciaranj - ciaranj.com

    This post has been brought to you by the letter C, and the number 7.


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    \n should work. What are you trying to do exactly?


  • Registered Users Posts: 2,660 ✭✭✭Baz_


    where are you outputting to ie. are you using the paint method. If you are then you have to specify the coordinates you want the string drawn at. I am assuming you're not however and if not then yes '\n' should work in almost all other cases.


  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    (yes i help ppl, because im nice!)

    u should make an array of strings, one for each line, then do a for loop:

    int yCoordinate = 20;
    for(int i = 0; i < stringArray.lenth; i++){
    g.drawString(stringArray, 20, yCoordinate);
    yCoordinate+=15;
    }

    this will draw each line starting at 20,20 and then 20,35 then 20,50 etc...


    - Dead Bank Clerk -
    [clergy]Altar Boy
    "Build a man a fire, and he'll
    be warm for a day. Set a man on
    fire, and he'll be warm for the
    rest of his life."

    [This message has been edited by DeadBankClerk (edited 12-04-2001).]


  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    or to make it even nicer u can use java to get the height of ur font (i dont know the method's name)

    and u could say:

    yCoordinate = yCoordinate + font.getHeight() + 3 //(a few pixles for space)


  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    If you want to get the pixel sizes of a font you need to use the FontMetrics class.
    FontMetrics fm = g.getFontMetrics(font);
    
    gets the FontMetrics object of your graphics context, and then you can use fm.getWidth() or fm.getHeight(), or a whole load of other methods that are listed in the API docs.


  • Advertisement
Advertisement