This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Text Generation Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Text Generation Method" Watch "Text Generation Method" New topic
Author

Text Generation Method

Brian Drelling
Ranch Hand

Joined: Oct 02, 2009
Posts: 42
I have a bit of a silly question. I have been thinking about it for a while!

If I wanted to give the impress that the program was typing in real time, as in, you see the letters appear one by one, pause at the end of a line, see the program hit enter twice, perhaps even a blinking cursor thrown in... how would you do it?

I'd imagine at the most basic level, you could just put text into a string and have it output character by character with a timer between each output that is very minimal so it gives the impression of typing. Simply pack the command for output within a while loop, and set the while integer to the same number of characters in the string. (I simplified this sentence immensely--I know.)

But is there an easier way to manage this?


Again, this is just curiosity.

Also, similar to system(cls) in C++, is there a "clear the console" function that I should be aware of that will wipe the slate clean once it hits that line?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I don't think more simpler than this:

And to clear the console using Java is impossible, though you can hit hundreds of linefeed to make the console clean. Also there is harder approach using JNI,
http://www.rgagnon.com/javadetails/java-0469.html


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Brian Drelling
Ranch Hand

Joined: Oct 02, 2009
Posts: 42
Ah. Interesting!

As for the console clearing, that is also interesting... How about a way of clearing an output screen? Say, for example, I wanted only text that has been input in the last 5 minutes to display. Are there way to clear out text older than 5 minutes if I have the program making a check, say, every 10 seconds or so?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

You're asking the same question, again. Its not straightforward to clear the cmd console. Just Google and you'll found the lots of link/posts discussing the same.
BTW, what's your need, can you try using Swing component.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
Look at these FAQ, no 19.
Brian Drelling
Ranch Hand

Joined: Oct 02, 2009
Posts: 42
No, I am not asking about clearing the console this time, but say a text area that is receiving inputs from a text field. Is this possible?

And thanks, I don't know how I missed that entry in the FAQ. The line was way too small!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
If you are using a text area (JTextArea, surely) it has a setText() method, so you can use that.
Brian Drelling
Ranch Hand

Joined: Oct 02, 2009
Posts: 42
Cool, thanks. That is what I was curious about. I'd be using that more than the console for my actual program.


Thanks, sorry if my questions were confusing!
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Brian Drelling wrote:Thanks, sorry if my questions were confusing!

Yes, I thought you're asking the same thing, regarding console(command prompt) and thanks for the FAQ link.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

You might find the java.awt.Robot class useful if you are using a GUI


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
Consider Paul's rocket mass heater.
 
subject: Text Generation Method
 
Similar Threads
write reversed lines to a file
I want to import single-spaced code
Japanese character not read or written correctly
Ranchers,Clarification on UTF-8 in Java
Byte vs Character streams