Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Java console functions?

Started by stefu Dec 5, 2001 at 9:09 AM 16 replies 5k views
Original Post
stefu
stefu
I know almost nothing about java console programming, could anyone help with few questions? How do I clear console? How to move the cursor position to decide where to print with System.out.println? And how can I make a pause for a period of time in milliseconds? Thnaks!
NuffSaid
NuffSaid
For making the system wait a specified number of seconds, take a look at System.wait(). That ought to do the trick.

Don''t think you can set the cursor at a specific position and output text.

For clearing the screen, don''t know if you can do that.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
WayfarerX
WayfarerX
quote:
Original post by stefu
How do I clear console?



You don't. Hold on...*digs through old posts*...ah, here it is. Martee answered this question awhile back:

quote:
Original post by Martee
Now, to answer your question ... there is no built-in method of clearing the screen. Here's why (from the #java FAQ):
I know every reader out there except those who understand Java is retching, wondering why Java doesn't provide such simple things as a "clear console" method.

The reason's pretty simple: Java doesn't really support the notion of a text console. Some machines don't have consoles at all, and other machines don't have standard mechanisms for clearing the console (for example, if you're using a special terminal that requires odd characters). Sun could have put these things in, sure... but why? The console is anathema to what Java is for, and how it's used.




quote:

How to move the cursor position to decide where to print with System.out.println?



Don't think you can do this either.

quote:

And how can I make a pause for a period of time in milliseconds?



Actually, it's Thread.sleep(num_milliseconds).



"So crucify the ego, before it's far too late. To leave behind this place so negative and blind and cynical, and you will come to find that we are all one mind. Capable of all that's imagined and all conceivable."
- Tool
------------------------------


Edited by - wayfarerx on December 5, 2001 12:11:19 PM
"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut
jermz
jermz
Java is fricking lame in that area. Theres no way to read characters from the keyboard until the user hits enter and theres no way to turn off echoing of input. Which makes it basically useless from any authentication angle
WayfarerX
WayfarerX
quote:
Original post by jermz
Java is fricking lame in that area. Theres no way to read characters from the keyboard until the user hits enter and theres no way to turn off echoing of input. Which makes it basically useless from any authentication angle



This is like calling a Pickup Truck lame because it can''t go 0-60 in 3.2 seconds (and it''s also flame-bait). This is not what Java was designed for. And if you really need that functionality bad, there''s always JNI.

"So crucify the ego, before it''s far too late. To leave behind this place so negative and blind and cynical, and you will come to find that we are all one mind. Capable of all that''s imagined and all conceivable."
- Tool
------------------------------
"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut
CaptainJester
CaptainJester
quote:
Original post by jermz
Java is fricking lame in that area. Theres no way to read characters from the keyboard until the user hits enter and theres no way to turn off echoing of input. Which makes it basically useless from any authentication angle


Java was not designed as a console app language. The console is only there for debugging purposes and to allow third party developers an easy way of making an IDE. How does it make it lame from any authentication angle?


---
Make it work.
Make it right.
Make it fast.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Jim_Ross
Jim_Ross
quote:
Original post by CaptainJester
[quote]Original post by jermz
Java is fricking lame in that area. Theres no way to read characters from the keyboard until the user hits enter and theres no way to turn off echoing of input. Which makes it basically useless from any authentication angle


Java was not designed as a console app language. The console is only there for debugging purposes and to allow third party developers an easy way of making an IDE. How does it make it lame from any authentication angle?



Doesn''t matter if it was designed to be lame or not, the way it functions now is lame. End of story. And java was not designed to run on servers serving web pages, nor was it designed to run on the desktop, and it wasn''t designed to run in a browser as an applet. Well WTF, okay if I''m not using java to program my cable box then I''m out of java''s intended target so I can''t bitch about anything. As a side note, my cable box and refriderator are some places that java has not shown up, but was touted as revolutionizing from the start.

Granted, I can print 100 blank lines to blank the console, but not being able to grab key presses until an enter is hit is just broken. I can grab key presses all day long on a Panel, why does the console have to be different? And don''t gimmie BS about how all consoles are so vastly different, GDI and X11 are vastly different...
WayfarerX
WayfarerX
quote:
Original post by Jim_Ross
Doesn''t matter if it was designed to be lame or not, the way it functions now is lame. End of story. And java was not designed to run on servers serving web pages, nor was it designed to run on the desktop, and it wasn''t designed to run in a browser as an applet. Well WTF, okay if I''m not using java to program my cable box then I''m out of java''s intended target so I can''t bitch about anything. As a side note, my cable box and refriderator are some places that java has not shown up, but was touted as revolutionizing from the start.

Granted, I can print 100 blank lines to blank the console, but not being able to grab key presses until an enter is hit is just broken. I can grab key presses all day long on a Panel, why does the console have to be different? And don''t gimmie BS about how all consoles are so vastly different, GDI and X11 are vastly different...



Hmmm...so how would this console functionality be implemented in the browser? Or on Mac OS 9 or less? Have System.clearConsole() throw a MethodNotImplemented exception? Yes, that''s much cleaner.

How hard would it be to create a simple little AWT component that acts exactly like the console you desire? (Hint: not hard)

And, like I said before, there''s always JNI...

"So crucify the ego, before it''s far too late. To leave behind this place so negative and blind and cynical, and you will come to find that we are all one mind. Capable of all that''s imagined and all conceivable."
- Tool
------------------------------
"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut
jermz
jermz
If you all really need to know the specific details, its for implenting various authentication procedures to Netware servers across different OS''s, and no, an AWT component is not possible. In my view, not being able to call something like getChar() or turn off echoing IS lame.

I do like java and use it a lot in both my work and pleasure. There just happens to be certain defficiencies with it in my opinion. Things like that mentioned, lack of enums, operator overloading and the pains it makes you go through for bit manipulations come to mind.

Well don''t use it then you say. The fact is every vendor and their mom are pushing java, including some with java-only solutions and apis.
CaptainJester
CaptainJester
quote:
Original post by Jim_Ross
Doesn''t matter if it was designed to be lame or not, the way it functions now is lame. End of story. And java was not designed to run on servers serving web pages, nor was it designed to run on the desktop, and it wasn''t designed to run in a browser as an applet. Well WTF, okay if I''m not using java to program my cable box then I''m out of java''s intended target so I can''t bitch about anything. As a side note, my cable box and refriderator are some places that java has not shown up, but was touted as revolutionizing from the start.



It may have started out as being designed for set top boxes, but in its current implementation, it is designed for every thing you said it is not. It is designed as platform independent language. Just because you can figure a way around your little problem, does not make the language lame. Smart programmers try to find a solution instead of blaming their tools. And that is what stefu is doing, tring to find a solution.



---
Make it work.
Make it right.
Make it fast.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
krez
krez
quote:
Original post by jermz
Well don''t use it then you say. The fact is every vendor and their mom are pushing java, including some with java-only solutions and apis.

There are 3 options then:
(1) Figure out a way around it (possible for most problems in most languages).
(2) Keep bitching and moaning (will not solve your problem of course).
(3) Give up on computers and become a burger-flipper or a guidance counsellor at some high-school (neither of these requires any intelligence or skills).


--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
jermz
jermz
Jeez, didn''t realize there were so many java zealots here. Did I ever say java was lame? No, I said in the area of console functionality it was lame, and it is.

And yes, the problem is already solved. Although having 4 different apps that do the same thing is hardly elegant in my opinion. Java''s portability is one of its major strengths and I wish I was able to use it for this case.

For those of you who are so quick to denigrate others who''s opinions differ from yours, i''m sorry.
Arild Fines
Arild Fines
Idiot /n/.
Person whose opinions differ from mine.

Psalm 137:9: "Happy shall he be, that taketh and dasheth thy little ones against the stones."
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Arild Fines
Arild Fines
On a more constructive note, it must be added that C/C++ has no more inherent console functionality than Java. Just as in Java, there is only the concept of an input, output and error stream.

Psalm 137:9: "Happy shall he be, that taketh and dasheth thy little ones against the stones."
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Kaijin
Kaijin
That''s so true, I completely forgot about that. I''m supprised that no one picked up on that point earlier.

I have to agree with the OP in that better console functionaliy would have been nice but I understand why it is missing.

Just out of interest how does MacOS display console output if it has not concept of a console?

- Kaijin
Fruny
Fruny
Try using ANSI/VT control codes.

clear console : {ESC}[2J
move to {ROW}, {COLUMN} : {ESC}[{ROW};{COLUMN}H

where {ESC} is ASCII 27.

Edited by - Fruny on December 8, 2001 11:31:04 AM
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Kaijin
Kaijin
Does that actually work?

- Kaijin

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.