• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Clearing the Screen URGENT !!!!!

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
can anybody tell how to clear the MS DOS / UNIX screen.
Actually my project require to clear the UNIX screen before displaying the data fetched from database.
eg., in DOS/UNIX we use cls to clear the screen. The same thing I want to do from my EJB Client before displaying data.
Please share your idea. Its URGENT !!!
Raj
 
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that your client is invoked from the command-line and wants to clear the terminal screen that it was invoked from.
Is that what you mean?
If you assume that your terminal screen is a standard 24 rows by 80 columns you could do something simple like looping on a call to System.out.println() 24 times. There are other ways to do it though.
If you are talking about a graphical screen the options would be very different. Can you clarify what you mean?
 
mr raj
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello George,
Thanks for reply. Yes, my client is invoked from the command-line and wants to clear the terminal screen that it was invoked from.
I am using UNIX and my screen has 24 rows. I already did using for loop calling System.out.println() 24 times. But the problem with this is that my screen gets cleared but it starts printing data form 25th line onward instead of 1st line. I want to print the data from the 1st line after clearing the screen.
Suggestion from rest is also welcome.
Its urgent !!!
Regards
Raj
 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the other area you might like to look at is the facilities offered by the awt package. You could get that to work using X windows, or if you have access to a web server/browser you could run an applet using awt.
But awt-related posts really belong in another of our forums.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My best guess is .. you can�t. Except for doing the println 24 times and start at the bottom. I would also guess that using Runtime.exec("cls") this should work in windows, but not in Unix.
 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how about having a look at the escape sequences available to you for your unix terminal type (eg. vt220, vt100, etc etc); it's possible that you could achieve what you are attempting through using those.
Ideally you are looking for a terminal screen drawing package like curses, but that's usually tied to a particular system whereas java isn't. I don't know of an equivalent written for java.
 
mr raj
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a lot guys
I will try this in different different ways and try to achieve it. Thanks a lot once again.
Regards
Raj
 
mr raj
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello sven veer,
I tried using Runtime Class, but I am getting Exception on NT...
Exception :java.io.IOException: CreateProcess: cls error=2
I tried on UNIX also, I am not getting any Exception. but the screen is not clearing..
My code is like this....
import java.io.*;
class clearScreenRuntime
{
static void main(String args[])
{
try
{
Runtime.getRuntime().exec("cls");
}
catch(IOException ioe)
{
System.out.println("Exception :"+ioe);
}
}
}
I wanted to know, is this the correct way of doing that....
If any modification requires then please let me know.
Suggestion from others is also welcome.
Regards
Raj
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the command in UNIX is clear, but first you need to know what OS is running, so
something like this:
try
{
String osName = System.getProperty("os.name" );
...
Runtime rt = Runtime.getRuntime();...
rt.exec...
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's this doing in the WLS forum? :roll: Oh well...
I think the CLS command in windoze is a "builtin" (to borrow a term from unix), and not an executable itself.
So you are probably going to have to exec something like "CMD /C CLS" or whatever. Not really sure. And this probably will only work on NT/Win2k - I think you may have to do something different on Win95/98.
In unix, the best you can do is the clear command, which asks terminfo about how to do a clear screen on the current terminal type. But note that just talks to the tty. If you are running the terminal in X, clear won't handle cases where your terminal (xterm, konsole, gnome-terminal, etc) is keeping history (scrollbar). You might be able to figure out how to signal the terminal to erase its history, but it'd be different for each one. I used to know how to do this for xterm (in vt100 mode), but those brain cells are long gone.
But if I ran your program and it cleared my terminal history, I'd be upset. I might have done something useful up there that I want to keep.
If you really need to have a universal "console" that does what you want, then you're probably going to have to write it in awt/swing....
reply
    Bookmark Topic Watch Topic
  • New Topic