This site requires JavaScript, please enable it in your browser!
Greenfoot back
kiarocks
kiarocks wrote ...

2011/7/1

How to use System.out.println()

kiarocks kiarocks

2011/7/1

#
how do you use System.out.println? I have it in my code, but where does it print
davmac davmac

2011/7/1

#
It prints to the terminal window, which will open if System.out.println() executes. If you can't see the terminal window,it might have appeared behind other windows (eg the main Greenfoot window). Minimize or move them to check.
GameCode GameCode

2011/7/5

#
System.out.println just works in Greenfoot and not in its jar. - Version. If you want to use something similar in .jar you could do this: GreenfootImage text = new GreenfootImage(x-size, y-size); setImage(text); text.drawString(".....YOUR...TEXT..........");
GameCode GameCode

2011/7/5

#
This creates an Image on which you can write sth. using drawString("");
danpost danpost

2011/7/5

#
GameCode wrote...
This creates an Image on which you can write sth. using drawString("");
What is 'sth'? Also, does it not matter that you used 'drawString' on 'text' after you 'setImage' to the object? And, what object is 'setImage' setting the image of? Sorry, for so many questions!
mjrb4 mjrb4

2011/7/6

#
Actually, the quickest way as of the latest version of Greenfoot to write text on a background is to use the new constructor in GreenfootImage here. That way you don't need to worry about wrapping and suchlike which isn't always the most straightforward of tasks.
kiarocks kiarocks

2011/7/6

#
which one?
danpost danpost

2011/7/6

#
I noticed that you can pass a 'newline' character to the GreenfootImage constructor you mention. What would the code look like, passing a 'newline' character?
davmac davmac

2011/7/6

#
Something like:
import java.awt.Color; /* at the top of the file */

    ...
    GreenfootImage textImage = new GreenfootImage("First line\nSecond line\nThird line", 12, Color.WHITE, Color.BLACK);
    ...
For readability you might prefer:
    GreenfootImage textImage = new GreenfootImage("First line\n"
        + "Second line\n"
        + "Third line", 12, Color.WHITE, Color.BLACK);
... or similar.
danpost danpost

2011/7/6

#
Thank you, Davin! Since I am fairly new to Java programming, it seems there is a lot I am not aware of within the language. But, I thank the good Lord that there are people who are willing to help; even if it's in the form of an answered question. Evidently, the backslash character cannot be output as part of the text, because it is used to signal the compiler that a control character is forthcoming. Are there any other characters that can be called in this fashion (using the '\' char)? And if so, what are they (code and description)? EXAMPLE: \n = 'newline' (line feed/carriage return)
mjrb4 mjrb4

2011/7/6

#
There's a full list here: http://www.java-tips.org/java-se-tips/java.lang/character-escape-codes-in-java.html \n, \\ and \" are the ones you'll most commonly use.
You need to login to post a reply.