Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

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

  • 12-04-2001 01:38PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


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


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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)


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭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