Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Text Generation Method

 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at these FAQ, no 19.
 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using a text area (JTextArea, surely) it has a setText() method, so you can use that.
 
Brian Drelling
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find the java.awt.Robot class useful if you are using a GUI
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic