This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to format user's on screen input?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am asked to write a program that takes user's input on screen(like when you use a System.in), however, when the user type something, it needs to appear italic on the screen. Does anyone know how to do that?

By the way, the user is supposed to type in one integer at the time, and I need to use the integers as my data.
 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set the Font on TextField (Swing/Awt), but not on the console input.
[ January 09, 2008: Message edited by: Abhinav Srivastava ]
 
Marshal
Posts: 65005
246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the problem with italic writing: for keyboard input I would find whichever method of the Scanner class takes an int as its input. You can pass System.in to Scanner in its constructor.

Try that and see whether it does what you want.
 
sheng liang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it seems like there is probably no way to change the font on JAVA console. Thanks for the time and replies though.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Text input/output consoles exist in most or all operating systems. Certain concepts (write some text, read some text, new-line etc.) are common to all of them. But more-advanced concept (fonts, colours, clear-screen etc.) are not available in all of them.

Java, being platform-independent (ish), takes a "lowest common denominator" approach, and only assumes that the console has features that all operating systems support. That means, no fonts, colours, clear-screen etc.

However, many operating systems' consoles understand control codes that will do things like change colour or clear the screen. If your application only needs to run on one operating system, you could find out what these are, for your particular console, and code them in Java.

Note that, in some operating systems (e.g. Unix), there are lots of different possible kinds of console, which would understand different control codes. In that situation, using control codes would restrict your application to a particular type of console (e.g. VT100 terminal) and a particular operating system.

Not good, but nevertheless, the possibility does exist.

Quite a lot of terminals understand ANSI escape codes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!