473,756 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clear the Screen

Hi,

I have done some research, trying to Clear The Screen in java code.

The first option was the obv:
system.out.prin t("\n\n\n\n\n\n \n\n\n\n\n\n");

then i heard about this method:
System.out.prin t((char)27 + "[2J");

However, it doen't work unless "ansi.sys" is loaded and very few WinXP
user's have this.

Any help appreciated in trying to solve this problem.

Cheers,
Dave
Jul 17 '05 #1
19 105826
It's kind of a hack, but what about this:

Runtime.exec("c ls");

This makes your application platform-dependent, but it looks like your
stated alternative does this as well.

-Nathan

"Dave" <bigdavepotnood le*SPAM*hotmail .com> wrote in message news:<3f******* *************** *@news-text.dial.pipex .com>...
Hi,

I have done some research, trying to Clear The Screen in java code.

The first option was the obv:
system.out.prin t("\n\n\n\n\n\n \n\n\n\n\n\n");

then i heard about this method:
System.out.prin t((char)27 + "[2J");

However, it doen't work unless "ansi.sys" is loaded and very few WinXP
user's have this.

Any help appreciated in trying to solve this problem.

Cheers,
Dave

Jul 17 '05 #2
Ive seen this question before- with no real solution.
Surely it wouldnt have been difficult to provide a clear screen, and even
basic screen cursor positioning?
It would make text-mode java alot more useful.

"Dave" <bigdavepotnood le*SPAM*hotmail .com> wrote in message
news:3f******** *************** @news-text.dial.pipex .com...
Hi,

I have done some research, trying to Clear The Screen in java code.

The first option was the obv:
system.out.prin t("\n\n\n\n\n\n \n\n\n\n\n\n");

then i heard about this method:
System.out.prin t((char)27 + "[2J");

However, it doen't work unless "ansi.sys" is loaded and very few WinXP
user's have this.

Any help appreciated in trying to solve this problem.

Cheers,
Dave

Jul 17 '05 #3

"Dave" <bigdavepotnood le*SPAM*hotmail .com> wrote in message
news:3f******** *************** @news-text.dial.pipex .com...
Hi,

I have done some research, trying to Clear The Screen in java code.

The first option was the obv:
system.out.prin t("\n\n\n\n\n\n \n\n\n\n\n\n");

then i heard about this method:
System.out.prin t((char)27 + "[2J");

However, it doen't work unless "ansi.sys" is loaded and very few WinXP
user's have this.

Any help appreciated in trying to solve this problem.

Cheers,
Dave


Look at jcurses on sourceforge.

Silvio Bierman
Jul 17 '05 #4
Printing out the form-feed character will clear the screen

System.out.prin t("\f");

Hope this helps!

Christian
Jul 17 '05 #5

"Denz" <RU*****@RUBBIS Hhotmail.com> wrote in message
news:Kv******** *******@news-server.bigpond. net.au...

Ive seen this question before- with no real solution.
Surely it wouldnt have been difficult to provide a clear
screen, and even basic screen cursor positioning?

It would make text-mode java alot more useful.


Unfortunately these tasks are inherently operating system-specific, and
cannot be implemented in any standard way across platforms. Some platforms,
in fact, don't even understand the concepts of 'screen', or 'cursor', so
wouldn't even have any use for classes that implemented these abstractions.
Even the 'standard' C and C++ languages which, like Java, aim for platform
independance, do not implement such functionality.

System-specific tasks such as these may be performed via:

* 'Runtime.getRun time().exec(... )'

* Writing Java Native Interface [JNI] routines which tap into
the relevant operating system functionality

The first option should really be seen as a 'quick and dirty' approach - it
allows you to perform certain system-specific tasks but with very little
control. A program, to be considered robust, would make no more than sparing
use of this facility. If you find you are relying on it heavily you may need
to seriously question whether Java is the ideal development tool for this
task [a scripting language (Perl, Python) might be more suitable ?], or more
of a development commitment needs be made by using JNI.

There is nothing inherently wrong with JNI except that its use helps defeat
one of Java's most important qualities - platform independance - and it
introduces 'weaknesses' into the application because program execution
occurs outside the control of the JVM, and any failure here could be
catastrophic. On the flipside, Java would be a very limited development
environment without it since it allows for the tapping into system-specific
functionality in a controlled, and efficient way.

So, to provide the facilities you seek, you need to implement suitable JNI
routines. Again, options are available:

* Tap into someone else's work. As another respondant has
already meantioned, the JCurses package provides a
reasonable suit of screen handling routines for the *NIX
and Windows-familiy platforms

* Write your own. This isn't as difficult as you might imagine,
and might be the best approach if all you require is a
few simple routines like:

- Clearing the screen
- Moving the cursor to specified positions
- Accepting input [say a single keystroke] without pressing
ENTER

A good start would be the JNI tutorial at the Sun site, and,
of course, perusal of the documentation for the system
functions implementing this functionality

Anyway, apologies for the longwindedness of the response. Hopefully, though,
some useful insights have been provided.

Cheers,

Anthony Borla
Jul 17 '05 #6

"Christian" <ja******@email user.net> wrote in message
news:32******** *************** ***@posting.goo gle.com...

Printing out the form-feed character will clear the screen

System.out.prin t("\f");

Hope this helps!


Sadly, it doesn't do as you expect - it's behaviour various with the
platform. Nice try, though :)

Cheers,

Anthony Borla
Jul 17 '05 #7

"Nathan Zumwalt" <na*****@hotmai l.com> wrote in message
news:52******** *************** ***@posting.goo gle.com...
It's kind of a hack, but what about this:

Runtime.exec("c ls");

This makes your application platform-dependent, but it looks
like your stated alternative does this as well.


Actually, this won't work. Yes, the 'cls' command is invoked, *but* it is
invoked in a new process ['command.com' or 'cmd.exe' is exected creating a
new process], and *does not* clear the Java application's console.

Cheers,

Anthony Borla
Jul 17 '05 #8
nos
But if they can implement "beep", and they do,
they should be able to implement "cls" too.

"Anthony Borla" <aj*****@bigpon d.com> wrote in message
news:g0******** ********@news-server.bigpond. net.au...

"Denz" <RU*****@RUBBIS Hhotmail.com> wrote in message
news:Kv******** *******@news-server.bigpond. net.au...

Ive seen this question before- with no real solution.
Surely it wouldnt have been difficult to provide a clear
screen, and even basic screen cursor positioning?

It would make text-mode java alot more useful.

Unfortunately these tasks are inherently operating system-specific, and
cannot be implemented in any standard way across platforms. Some

platforms, in fact, don't even understand the concepts of 'screen', or 'cursor', so
wouldn't even have any use for classes that implemented these abstractions. Even the 'standard' C and C++ languages which, like Java, aim for platform
independance, do not implement such functionality.

System-specific tasks such as these may be performed via:

* 'Runtime.getRun time().exec(... )'

* Writing Java Native Interface [JNI] routines which tap into
the relevant operating system functionality

The first option should really be seen as a 'quick and dirty' approach - it allows you to perform certain system-specific tasks but with very little
control. A program, to be considered robust, would make no more than sparing use of this facility. If you find you are relying on it heavily you may need to seriously question whether Java is the ideal development tool for this
task [a scripting language (Perl, Python) might be more suitable ?], or more of a development commitment needs be made by using JNI.

There is nothing inherently wrong with JNI except that its use helps defeat one of Java's most important qualities - platform independance - and it
introduces 'weaknesses' into the application because program execution
occurs outside the control of the JVM, and any failure here could be
catastrophic. On the flipside, Java would be a very limited development
environment without it since it allows for the tapping into system-specific functionality in a controlled, and efficient way.

So, to provide the facilities you seek, you need to implement suitable JNI
routines. Again, options are available:

* Tap into someone else's work. As another respondant has
already meantioned, the JCurses package provides a
reasonable suit of screen handling routines for the *NIX
and Windows-familiy platforms

* Write your own. This isn't as difficult as you might imagine,
and might be the best approach if all you require is a
few simple routines like:

- Clearing the screen
- Moving the cursor to specified positions
- Accepting input [say a single keystroke] without pressing
ENTER

A good start would be the JNI tutorial at the Sun site, and,
of course, perusal of the documentation for the system
functions implementing this functionality

Anyway, apologies for the longwindedness of the response. Hopefully, though, some useful insights have been provided.

Cheers,

Anthony Borla

Jul 17 '05 #9
While it was 9/1/04 3:04 pm throughout the UK, nos sprinkled little
black dots on a white screen, and they fell thus:
But if they can implement "beep", and they do,
they should be able to implement "cls" too.

<snip top of upside-down reply>

That's because BEL is a standard ASCII character (code 7) and it's
pretty much standard that any terminal/console would render it by
beeping. OTOH, for some reason I can't imagine FF (12) doesn't
standardly mean clear screen, and nor does any other ASCII string.

But I agree that having a portable means of screen clearing would be
handy. BTW, have the rest of you people stopped telling people to try
what you can't be bothered to try for yourself?

Stewart.

--
My e-mail is valid but not my primary mailbox, aside from its being the
unfortunate victim of intensive mail-bombing at the moment. Please keep
replies on the 'group where everyone may benefit.
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
73326
by: NeoPhreak | last post by:
How would you clearn the screen in a console program??? Thanks NeoPhreak >.<
0
2777
by: Peter | last post by:
I am just trying to learn python, to use for some fairly basic command line utilities which will run in either Windows/DOS or Linux. I cannot find a platform neutral way of manipulating the screen. I don't want to do anything complex, but just:- 1. Clear the screen 2. Print a string at an arbitrary x,y position 3. Receive a single key stroke It seems that under Linux the curses module will do all this and more
20
8155
by: ritchie | last post by:
Hi, I am trying to clear the screen in my program. I am loking for something that will work on all compilers, especially Borland & MS Visual Studio 6. On Visual studio I used 'system("cls");' and this works fine but this won't work for Borland. On Borland I used 'clrscr() ' function and it worked ok, but not for Visual Studio.
4
25754
by: John | last post by:
Hi I have the following in a Perl script. I just want to "clear screen" but it does not work. I don't think I've got my client and server sides confused. Any ideas? <SCRIPT Language="JavaScript"> moveTo (0,0);
8
64985
by: REDBAIT | last post by:
Hi Guys, Am using Windows 2000 and Dev C++ to create C programs. I'm trying to use clear screen and other graphic functions such as positioning output on screen. Have seen some documents that suggest i use curses.h or system("clear") for clear screen, for example but all this has failed.
0
1620
by: sajithamol | last post by:
I have an Applet that has three buttons on it, one being a clear screen button. I have it setup right now so it draws a rectangle the size of the applet and fills it with the background color. But when it does that my other two buttons disappear until I mouse over them again. Is there a better way to clear screen or anyway for the buttons to show back up after the "clear screen"?
2
3803
by: owl | last post by:
and here I thought I was going to finally be able to change the world AND contribute back to python with my amazing clear screen extension - but I can't get it to work. ;( Copying from ZoomHeight.py and someone else's clever print suggestion: ------------------------------------------------- # My Clear extension: clear a window class Clear:
9
19181
by: pbd22 | last post by:
Hi. Does anybody know how to issue a clear screen command like DOS "cls" in a telnet session? Thanks!
5
3470
by: Kid Programmer | last post by:
Hello guys. I was wondering how you can clear the screen in a java program. Here is the code for my program: import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.BorderFactory; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; public class GUI {
1
19680
by: sganeshsvk | last post by:
i want to clear the screen command prompt for mysql in windows XP... In linux we use (CTRL + L) for clear the screen in mysql prompt.... i already use this command ( \c ) then ( \! clear ) for clear screen in Mysql windows XP... Plz sir, i want reply must......
0
9455
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.