
-----------------------------------
underdog
Sat Jan 14, 2006 10:03 pm

positioning output
-----------------------------------
hey guys,

i kinda just started programming this year and i would like to know how to position text output by the 'c.print' method (c being my console). id there any way to position it without using '\t' or '\n' ?

For example:
i type in: c.println ("Hello World");
and I want it to appear as

-----------------------------------------------------------------
|                                                                               |
|                                                                               |
|                                                                               |
|                                                                               |
|                                       Hello World                                                                                                                                                                             
|                                                                               |
|                                                                               |
|                                                                               |
|                                                                               |
|                                                                               |
|                                                                               |
|                                                                               |
-------------------------------------------------------------------

thanks,

underdog

-----------------------------------
underdog
Sat Jan 14, 2006 10:04 pm


-----------------------------------
EDIT: ^ the 'Hello World should be more to the right

-----------------------------------
idtt2s
Sun Jan 15, 2006 10:03 am


-----------------------------------
I don't know how c.println works, I'm guessing it's the HSA Console class everyone complains about. But for outputting text, using the core Java classes should be simple enough.

Anyways, you need a seperate method to print the print the text the way you want it.

For example, 

public void printAwkwardString(String string) {
    System.out.print("-----------------);
    System.out.print(string);
    System.out.print("-----------------);
}


A would like to ask once more, how do I post code with syntax highlighting?

And to call it, in you main class, do

printAwkwardString("Hello World");

And to call it,

-----------------------------------
idtt2s
Sun Jan 15, 2006 10:05 am


-----------------------------------
Sorry for the double post, but is this the only forum in the world that doesn't allow editing?

-----------------------------------
Cervantes
Sun Jan 15, 2006 10:32 am


-----------------------------------
CompSci.ca allows editing, just not in the Help forums, because people were removing their questions after receiving help.

Syntax highlighting: 
c.print("", 10) // 10 is the field width
c.print("Hello World")


-----------------------------------
JackTruong
Sun Jan 15, 2006 10:37 am


-----------------------------------
Using c.print() (or println()) can have two parameters;

c.print("Text");
c.print("Text",20);

In the first example, the console prints from the text cursor position, which is the last place where text had been entered.

In the second example, it also prints from the text cursor, but allocates 20 spaces for the word. If the word is less than 20 characters, it adds 20 minus the word length spaces. If the word is 20 characters, then it doesn't add spaces. And if the word is over 20 characters, then it takes up more than 20 spaces.

Looking at the source code for the hsa.ConsoleParent class:
    public void print (String text, int fieldSize)
    {
        StringBuffer padding = new StringBuffer ();
        
        for (int cnt = 0 ; cnt < fieldSize - text.length () ; cnt++)
        {
            padding.append (' ');
        }
        print (text + padding);
    } // print (String, int)

You can see that the above is true.

----

I noticed Cervantes already posted when I previewed this post.

-----------------------------------
ste_louis26
Sun Jan 15, 2006 3:54 pm


-----------------------------------
I believe you could also use c.setCursor (x,y) to position text

x is horizontal distance
y vertical distance
do

c.setCursor (3,10);
c.print ("Hello World");


also could do drawString if ur allowed

-----------------------------------
underdog
Tue Jan 17, 2006 9:37 pm


-----------------------------------
thanks guys, i discovered drawString, etc.

-----------------------------------
GoVikingsGo
Tue Jan 17, 2006 10:39 pm


-----------------------------------
the best way to do it is to first off is too use c.setCursor (x,y) if u know Turing its like locate (x,y) it sets the cursor at the required location

Dont use c.drawString unless for decoration, cause it has like all fonts and u have to make an object etc

So the best way is to:


c.setCursor (5,5);
c.println ("Hello World");
[/quote]
