positioning output
Author |
Message |
underdog
|
Posted: Sat Jan 14, 2006 10:03 pm Post subject: 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
underdog
|
Posted: Sat Jan 14, 2006 10:04 pm Post subject: (No subject) |
|
|
EDIT: ^ the 'Hello World should be more to the right |
|
|
|
|
|
idtt2s
|
Posted: Sun Jan 15, 2006 10:03 am Post subject: (No subject) |
|
|
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,
code: |
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
code: |
printAwkwardString("Hello World");
|
And to call it, |
|
|
|
|
|
idtt2s
|
Posted: Sun Jan 15, 2006 10:05 am Post subject: (No subject) |
|
|
Sorry for the double post, but is this the only forum in the world that doesn't allow editing? |
|
|
|
|
|
Cervantes
|
Posted: Sun Jan 15, 2006 10:32 am Post subject: (No subject) |
|
|
CompSci.ca allows editing, just not in the Help forums, because people were removing their questions after receiving help.
Syntax highlighting: [ syntax="Java"] code here [ /syntax], without the spaces.
Underdog, you could do something like this:
Java: |
c.print("", 10) // 10 is the field width
c.print("Hello World")
|
|
|
|
|
|
|
JackTruong
|
Posted: Sun Jan 15, 2006 10:37 am Post subject: (No subject) |
|
|
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:
Java: | 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
|
Posted: Sun Jan 15, 2006 3:54 pm Post subject: (No subject) |
|
|
I believe you could also use c.setCursor (x,y) to position text
x is horizontal distance
y vertical distance
do
code: |
c.setCursor (3,10);
c.print ("Hello World");
|
also could do drawString if ur allowed |
|
|
|
|
|
underdog
|
Posted: Tue Jan 17, 2006 9:37 pm Post subject: (No subject) |
|
|
thanks guys, i discovered drawString, etc. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
GoVikingsGo
|
Posted: Tue Jan 17, 2006 10:39 pm Post subject: (No subject) |
|
|
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:
code: |
c.setCursor (5,5);
c.println ("Hello World");
| [/quote] |
|
|
|
|
|
|
|